Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #6121 > unrolled thread
| Started by | Tim Golden <mail@timgolden.me.uk> |
|---|---|
| First post | 2011-05-24 09:46 +0100 |
| Last post | 2011-05-24 09:46 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit Tim Golden <mail@timgolden.me.uk> - 2011-05-24 09:46 +0100
| From | Tim Golden <mail@timgolden.me.uk> |
|---|---|
| Date | 2011-05-24 09:46 +0100 |
| Subject | Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit |
| Message-ID | <mailman.2005.1306226775.9059.python-list@python.org> |
On 24/05/2011 09:31, Cathy James wrote:
> dear mentor,
> I need help with my code:
> 1) my program won't display file contents upon opening
> #1) open file and display current file contents:
> f = open ('c:/testing.txt'', 'r')
> f.readlines()
If you're running this in an interactive interpreter, I would
expect it to show a list of lines (assuming c:/testing.txt has
something in it...). If you're running it as a program, though,
it won't show anything: you need to actually output the result
of the expression f.readlines (). It only happens at the
interpreter as a development convenience:
f = open ("c:/testing.txt", "r")
print f.readlines ()
# or print (f.readlines ()) if you're in Python 3
TJG
Back to top | Article view | comp.lang.python
csiph-web