Fluffy
Fluffy

Reputation: 28362

Reading corrupted file in python

I've got a file, that looks like this alt text http://img40.imageshack.us/img40/4581/crapq.png 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

Upvotes: 1

Views: 3443

Answers (1)

jfs
jfs

Reputation: 414179

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

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

Upvotes: 6

Related Questions