+ 2

can you upload images into a python code? if you can ... how?

18th Jun 2018, 7:24 PM
Arketa
Arketa - avatar
2 Antworten
+ 7
Hello, Arketa ! The first method The first method uses the module urllib (or urllib2). Let there be a link to some img image. The method looks like this: import urllib resource = urllib.urlopen (img) out = open ("... \ img.jpg", 'wb') out.write (resource.read ()) out.close () Here you need to pay attention that the recording mode for images is 'wb' (binary), and not just 'w'. 2nd method The second method uses the same urllib. In the future it will be shown that this method is slightly slower than the first (negative shade of the parsing speed factor is ambiguous), but worthy of attention because of its brevity: import urllib urllib.urlretrieve (img, "... \ img.jpg") Moreover, it should be noted that the function urlretrieve in the library urllib2 for reasons unknown to me (who can tell by what) is missing. The third method The third method uses the requests module. The method has the same order of speed of unloading pictures with the first two methods https://m.habr.com/post/210238/
18th Jun 2018, 7:29 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 1
ok thank you. would you do the same for an animation?
18th Jun 2018, 7:32 PM
Arketa
Arketa - avatar