Problems with io.

Karl Scalet news at yebu.de
Wed Jul 2 09:38:16 EDT 2003


freone schrieb:
> 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?

Assuming file 'test.txt' exists, your program should work.
In your case, you can ommit the + in 'r+', or the 'r+' alltogether.
Also, choosing file as a variable is not a good idea, as it
hides the builtin function (which could have been used
as well instead of open()).

What your problem might be, is not seeing anything as
you do not fetch the result of fil.readlines().
So just do
lines = fil.readlines()
print lines
#or
for line in lines:
     print line


> 
> (sorry for such ask but it is anonyoning me why it doesn't work, if u
> don't reply i'll understand it)





More information about the Python-list mailing list