0

<code=python>
>>>f = file("sendBuffer.dat","rb")
>>> f.read()
'\x81x\x00>\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00A .\x00\x10aG\xce\x00
\x00\x00\x00\x00\x00\x00\x00\x01\xcd\xccL@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x
00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
>>> text = f.read()
>>> print text
</code>

In the above code f.read() prints the data, but when i say print text or print length of text it returns NULL and zero respectively. Any Ideas?

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by vsagarmb
0

An open file has a concept of 'position in the file'. After the first call to f.read(), the file position is at the end of the file. If you read again, you read an empty string. The solution is to go back to the beginning of the file

f.read()
f.seek(0) # go back to the beginning
text = f.read() # read again

Edited by Gribouillis: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.