Basic file operation questions

Michael.Lang at jackal-net.at Michael.Lang at jackal-net.at
Thu Feb 3 07:14:23 EST 2005


In article <mailman.1808.1107431422.22381.python-list at python.org>, Peter Nuttall wrote:
> 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()

sure you can 

f = open("data.txt", "rb")
while [ 1 ]:
	line = f.readlines()
	if not line:	break
	line = somethingelse ...
f.close()

> 
> Pete



More information about the Python-list mailing list