tags:

views:

47

answers:

1

Hello. I've got a file, that looks like this alt text Now there are 5 lines shown. However running this script

with open('hello.txt', 'r') as hello:
    for line in hello:
        print line,

gives

num 1
ctl00$header1$Login1$txtUserName=ыют;CBШ▌

and that's all. How can I read entire file? TIA

+5  A: 
entire_file = open('hello.txt', 'rb').read()

print 'number of \\n: %d, number of bytes %d' % (
    entire_file.count('\n'), len(entire_file))
J.F. Sebastian
@roddik: Yes, add the 'b' flag to open() to indicate you want the file to be handled as a binary file (e.g. a sequence of bytes).
Bandi-T