Trying to understand how you're supposed to read files in python. This is what I've done and it isn't working quite properly:
import os.path
filename = "A 180 mb large file.data"
size = os.path.getsize(filename)
f = open(filename, "r")
contents = f.read()
f.close()
print "The real filesize is", size
print "The read filesize is", len(contents)
f = open(filename, "r")
size = 0
while True:
contents = f.read(4)
if not contents: break
size += len(contents)
f.close()
print "this time it's", size
Outputs:
The real filesize is 183574528
The read filesize is 10322
this time it's 13440
Somebody knows whats going on here? :)