Skip to content Skip to sidebar Skip to footer

What's With Binary Files On Windows?

I made a script to download a file, but it only works on Unix/Linux/OSX when I'm downloading binary executables, swf's, images, etc \#Modfied section from PWB.py import sys if

Solution 1:

Open binary files in binary mode.

z = open("intro.swf","wb")

Solution 2:

From the Python 2 documentation:

On Windows, 'b' appended to the mode opens the file in binary mode, so there are also modes like 'rb', 'wb', and 'r+b'. Python on Windows makes a distinction between text and binary files; the end-of-line characters in text files are automatically altered slightly when data is read or written. This behind-the-scenes modification to file data is fine for ASCII text files, but it’ll corrupt binary data like that in JPEG or EXE files. Be very careful to use binary mode when reading and writing such files. On Unix, it doesn’t hurt to append a 'b' to the mode, so you can use it platform-independently for all binary files.

Solution 3:

Use z=open("intro.swf","wb") on Windows to open the file in binary mode.

http://docs.python.org/tutorial/inputoutput.html

Solution 4:

You have to use "wb" in the argument for open() to get it in binary mode - the default is text mode which converts \n to CR/LF.

Post a Comment for "What's With Binary Files On Windows?"