opening a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pjpcolo
    New Member
    • May 2007
    • 1

    opening a file

    hI, I know nothing about Python but it's on my computer. When I try to open a file, it pops up and closes immediately. How do I change that?
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by pjpcolo
    hI, I know nothing about Python but it's on my computer. When I try to open a file, it pops up and closes immediately. How do I change that?
    Python "scripts" are callable from the command-line. With the command-line shell, you'll see the output of the "script". Or you can start IDLE and open the file, then Run Module (F5) from the Run (I think) menu. If you are on Windows, you should be able to right-click and pull-down to Edit with IDLE, but this starts IDLE in it's single-thread mode (OK for starting out, but could cause problems later on).

    Comment

    • dshimer
      Recognized Expert New Member
      • Dec 2006
      • 136

      #3
      What operating system?

      How are you interacting with python, do you just type "python" to start the interpreter, or are you working within an IDE like Idle, or pythonwin?

      In general though, when you open a file, you are just creating an instance of an open "file object" (see docs), or example
      Code:
      >>> f=open('/tmp/tmp.txt','r')
      >>> print f
      <open file '/tmp/tmp.txt', mode 'r' at 0x008E72A8>
      it is after that, the fun begins as you can interact with it with methods like readlines() and such.

      Comment

      Working...