2010-01-23 111 views

回答

6
entire_file = open('hello.txt', 'rb').read() 

print 'number of \\n: %d, number of bytes %d' % (
    entire_file.count('\n'), len(entire_file)) 
+0

@roddik:是的,將'b'標誌添加到open()以表明您希望將該文件作爲二進制文件(例如字節序列)處理。 – 2010-01-23 18:51:28