[Tutor] How to convert binary files back to text files?
prasad rao
prasadaraon50 at gmail.com
Sat Aug 29 15:02:14 CEST 2009
Hello!
I want to convert compiled files to text files.
I believe compiled files are binary files.
I am able to convert a given string to binary and back to text.
But when it comes to a file it is proving to be impossible.
<code>
def p(a):
s=open(a,'rb')
for x in s:
d=map(lambda y:chr(int(y,2)),x)
print d
s.close()
>>> p("C:/pp.txt")
Traceback (most recent call last):
File "<pyshell#53>", line 1, in <module>
p("C:/pp.txt")
File "<pyshell#52>", line 5, in p
d=map(lambda y:chr(int(y,2)),x)
File "<pyshell#52>", line 5, in <lambda>
d=map(lambda y:chr(int(y,2)),x)
ValueError: invalid literal for int() with base 2: 'f'
</code>
Please some one point where the problem is.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090829/9d6df522/attachment.htm>
More information about the Tutor
mailing list