Hi,
I'm trying to open a file (any file) in binary mode and save it inside
a new text file.
After that I want to read the source from the text file and save it
back to the disk with its original form. The problem is tha the binary
source that I extract from the text file seems to be diferent from the
source I saved. Here is my code:
1)
handle=file('im age.gif','rb')
source=handle.r ead()
handle.close()
if I save the file directly everything is well :
2A)
handle=file('im ageDuplicated.g if','wb')
handle.write(so urce)
handle.close()
the file imageDuplicated .gif will be exactly the same as the original
image.gif.
But if I save the source to a text file I have porblem :
2B)
handle=file('te xt.txt','w')
handle.write(so urce)
handle.close()
handle=file('te xt.txt','r')
source2=handle. read()
handle.close()
handle=file('im ageDuplicated.g if','wb')
handle.write(so urce2)
handle.close()
the files are completly different and I even cant display the image
from the imageDuplicated .gif .
something changes when I save the source in the text file because in
2B) source == source2 returns a False .
I suspect that maybe the encoding is making a conflict but I don't know
how to manipulate it...
Every help is welcome, thanks.
I'm trying to open a file (any file) in binary mode and save it inside
a new text file.
After that I want to read the source from the text file and save it
back to the disk with its original form. The problem is tha the binary
source that I extract from the text file seems to be diferent from the
source I saved. Here is my code:
1)
handle=file('im age.gif','rb')
source=handle.r ead()
handle.close()
if I save the file directly everything is well :
2A)
handle=file('im ageDuplicated.g if','wb')
handle.write(so urce)
handle.close()
the file imageDuplicated .gif will be exactly the same as the original
image.gif.
But if I save the source to a text file I have porblem :
2B)
handle=file('te xt.txt','w')
handle.write(so urce)
handle.close()
handle=file('te xt.txt','r')
source2=handle. read()
handle.close()
handle=file('im ageDuplicated.g if','wb')
handle.write(so urce2)
handle.close()
the files are completly different and I even cant display the image
from the imageDuplicated .gif .
something changes when I save the source in the text file because in
2B) source == source2 returns a False .
I suspect that maybe the encoding is making a conflict but I don't know
how to manipulate it...
Every help is welcome, thanks.
Comment