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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder3.xlned.com!newsfeed10.multikabel.net!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <mail@timgolden.me.uk>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'interpreter': 0.07; 'subject:while': 0.07; 'python': 0.08; 'from:addr:timgolden.me.uk': 0.09; 'from:name:tim golden': 0.09; 'interpreter,': 0.09; 'message-id:@timgolden.me.uk': 0.09; 'output': 0.11; 'subject:file': 0.14; 'wrote:': 0.14; '"r")': 0.16; "'r')": 0.16; '(assuming': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:user': 0.16; 'cc:addr:python-list': 0.17; 'header:In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'expect': 0.25; 'subject:HELP': 0.29; "won't": 0.30; 'cc:addr:python.org': 0.30; 'tjg': 0.30; 'print': 0.31; 'expression': 0.32; 'list': 0.33; 'actually': 0.33; 'lines': 0.33; 'file': 0.34; 'header:User- Agent:1': 0.35; 'open': 0.36; 'program,': 0.37; 'running': 0.37; 'something': 0.37; 'subject:: ': 0.38; 'received:192': 0.38; 'current': 0.40; 'help': 0.40; 'subject:, ': 0.60; 'dear': 0.63; 'from:addr:mail': 0.65; 'show': 0.66; 'to:none': 0.93; 'subject:\t': 0.93
Date Tue, 24 May 2011 09:46:11 +0100
From Tim Golden <mail@timgolden.me.uk>
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.17) Gecko/20110414 Lightning/1.0b2 Thunderbird/3.1.10
MIME-Version 1.0
CC python-list@python.org
Subject Re: NEED HELP- read file contents, while loop to accept user input, and enter to exit
References <BANLkTinh6V3-DtdU5davGdP5a53a2eDF_Q@mail.gmail.com>
In-Reply-To <BANLkTinh6V3-DtdU5davGdP5a53a2eDF_Q@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2005.1306226775.9059.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 82.94.164.166
X-Trace 1306226775 news.xs4all.nl 49038 [::ffff:82.94.164.166]:35912
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6121

Show key headers only | 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