By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,790 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

opening a file

P: 1
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?
May 18 '07 #1
Share this Question
Share on Google+
2 Replies


bartonc
Expert 5K+
P: 6,596
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).
May 18 '07 #2

dshimer
Expert 100+
P: 136
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
Expand|Select|Wrap|Line Numbers
  1. >>> f=open('/tmp/tmp.txt','r')
  2. >>> print f
  3. <open file '/tmp/tmp.txt', mode 'r' at 0x008E72A8>
  4.  
it is after that, the fun begins as you can interact with it with methods like readlines() and such.
May 18 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.