Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6121

Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit

Date 2011-05-24 09:46 +0100
From Tim Golden <mail@timgolden.me.uk>
Subject Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit
References <BANLkTinh6V3-DtdU5davGdP5a53a2eDF_Q@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2005.1306226775.9059.python-list@python.org> (permalink)

Show all headers | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web