This code is working well:
f = open("C:/Dokumente und Einstellungen/schnei17/Desktop/a.txt", "r")
f.seek(0)
print f.read(200)
Bu开发者_Go百科t here read() doesn't work properly:
print f.read(2000)
The output is very short now. Is this a bug? The file contains unicode-data. Thanks in advance.
Solution:
f = open("C:/Dokumente und Einstellungen/schnei17/Desktop/a.txt", "rb")
f.seek(0)
print f.read(200)
What does this produce?
import os
filename = "C:/Dokumente und Einstellungen/schnei17/Desktop/a.txt"
print "Filesize: %s" % (os.path.getsize(filename),)
f = open(filename, "r")
data = f.read(2000)
print "Read %s bytes" % (len(data),)
Filesize: 62606 Read 692 bytes
And changing the read mode to binary?
import os
filename = "NewProv.txt"
print "Filesize: %s" % (os.path.getsize(filename),)
f = open(filename, "rb")
data = f.read(2000)
print "Read %s bytes" % (len(data),)
精彩评论