On 2011-08-23, Steven D'Aprano <[email protected]> wrote:
> Yingjie Lin wrote:
>
>> Hi Python users,
>>
>> I just realize that my post yesterday shouldn't be specifically for
>> mechanize. It should be a general question for file-like objects.
>>
>>>>> f = open('my_file.txt')
>>>>> print f.readlines()
>> ( prints a list of strings
>>>>> print f.readlines()
>> []
>
> Once you've read the file, the file pointer is now at the end of the file.
> To go back to the beginning of the file and read it again, you have to use
> the seek method:
>
> f.seek(0)
It's too bad Python doesn't support the f.rewind() spelling for that
operation. Rewinding disk files always made me smile...
--
Grant Edwards grant.b.edwards Yow! Did I say I was
at a sardine? Or a bus???
gmail.com
--
http://mail.python.org/mailman/listinfo/python-list