python byte file readign screwup
so I have
f = open(infile, mode = 'rb')
while f:
line = f.read(int(k))
ints = list(line)
print(type(line))
etc etc....theoretically this is supposed to read the file in byte mode since I added 'b' to the mode...but then when the console outputs the print(type开发者_如何转开发(line))....it would return the type as string rather than bytes.....what am I doing wrong?
They are still characters. All 'b' does is prevent line endings from being changed. EDIT: Actually the byte type is new in python 3 and using 'b' will return a bytearray.
I think, you should be using Python 2. (2.6/2.7) There str is a 8bit byte, so the the out is displayed as 'str'. If you use Python 3 with your above code, you will find that type(line) will display class 'bytes'
.
精彩评论