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?
opening a file
Collapse
X
-
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).Originally posted by pjpcolohI, 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? -
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
it is after that, the fun begins as you can interact with it with methods like readlines() and such.Code:>>> f=open('/tmp/tmp.txt','r') >>> print f <open file '/tmp/tmp.txt', mode 'r' at 0x008E72A8>Comment
Comment