What about binary files on Windows?

I made a script to download the file, but it only works on Unix / Linux / OSX when I load binary executables, swf, images, etc.

\#Modfied section from PWB.py  
import sys  
if sys.version_info<(2,8):  
    import urllib as request  
else:  
    import urllib.request as request  
x=request.urlopen("http://homestarrunner.com/intro.swf")  
y=x.read()  
x.close()  
z=open("intro.swf","w")  
z.write(y)  
z.close() 

I will get the file and the usual unreadable garbage in the file, but it will be unreadable.

It seems that binaries always have such problems on Windows. Why is this?

PS. How can I write my Python code so that it loads?

0
source share
4 answers

From the Python 2 documentation :

Windows, 'b' , , "rb", "wb", 'r + b'. Python Windows ; . ASCII , itll JPEG EXE. , . Unix, 'b' , - .

+6

.

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

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

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

0

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

0
source

Source: https://habr.com/ru/post/1541816/


All Articles