Problems with io.

Bob Gailer bgailer at alum.rpi.edu
Wed Jul 2 17:37:45 CEST 2003


At 06:16 AM 7/2/2003 -0700, freone wrote:

>Hello,
>some time ago I started to learn python, today i wanted make a very
>samll and simple program.
>file = open("test.txt", "r+")
>file.readlines()
>file.close()
>And it doesn't work...
>Why?

ATTENTION EVERYONE who submits a problem...PLEASE PLEASE PLEASE tell us 
what the problem is (how you are running it, expected behavior, actual 
results, exceptions, ...). Without that info we have NO way to help, and we 
are frustrated as a result.

Having said that here's my guess. If you are running this code from a file 
(either by C>python filename.py or by import filename and you see no output 
then the program IS working.

If you want output you'll need to use print, as in print file.readlines().

BTW file is a python builtin, and it's a good idea to not use it as a 
variable. In fact file is the new and preferred alternative to open:

fileA = file("test.txt", "r+")
fileA.readlines()
fileA.close()


Bob Gailer
bgailer at alum.rpi.edu
303 442 2625
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.492 / Virus Database: 291 - Release Date: 6/24/2003


More information about the Python-list mailing list