我有一个文件,看起来像alt text http://img40.imageshack.us/img40/4581/crapq.png 现在显示了5行。但运行此脚本
with open('hello.txt', 'r') as hello:
for line in hello:
print line,
给出
num 1
ctl00$header1$Login1$txtUserName=ыют;CBШ▌
就是这样。我怎么能读完整个文件? TIA
答案 0 :(得分:6)
entire_file = open('hello.txt', 'rb').read()
print 'number of \\n: %d, number of bytes %d' % (
entire_file.count('\n'), len(entire_file))