Basic file operation questions

Peter Nuttall psn at compsoc.dur.ac.uk
Thu Feb 3 06:50:21 EST 2005


On Wed, Feb 02, 2005 at 11:47:41PM -0500, Caleb Hattingh wrote:
> Hi Alex
> 
> Assuming you have a file called "data.txt":
> 
> ***
> f = open('data.txt','r')
> lines = f.readlines()
> f.close()
> for line in lines:
>     print line
> ***
>

Can you not write this:

f=open("data.txt", "r")
for line in f.readlines():
	#do stuff to line
f.close()

Pete



More information about the Python-list mailing list