<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?

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

Thanks a lot Gribouillis. It Worked!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.