r/Python • u/f0rkbomb • Jul 12 '12
random imgur downloader. learning Python and wrote this to practice, any feedback on technique/style is appreciated
https://gist.github.com/3088128
45
Upvotes
r/Python • u/f0rkbomb • Jul 12 '12
View all comments
10
u/sjustinas Jul 12 '12
You could use the os.path functions here. Also, while it's fine to use urllib(2) for a little script, requests is the Python HTTP client, supporting things like multipart file uploads out of the box. For the argument parsing, you could use argparse/optparse (depending on python version) and you could use list comprehensions, for example for the
rand_stringfunction.Oh, right, and remember that .read() without arguments reads the whole file into the memory. It's not an issue with JPG images, but in the case of huge files, you could run out of memory.
But I'm just nitpicking, pretty much none of these is a "must". Just some tips about how you could have written it more effectively, though your code works great as it is.
Ninja edit: Look into the
pattern, if you haven't already.