View Full Version: How do I read a file in Python?

C++ Learning Community > Other Programing Languages > How do I read a file in Python?


Title: How do I read a file in Python?


Dragon - January 12, 2004 07:15 AM (GMT)
This is similar to the code I tried to read a specific number of bytes from a file:

CODE
f.open("/home/rli/file")
f.seek(4,0)
f.tell()
data = f.read(4)
data


I want it to read the first four bytes from a file, but it displays ' '. How do I read the first few bytes of a file? Any help is appreciated.




* Hosted for free by InvisionFree