r/Python • • 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

72 comments sorted by

View all comments

29

u/say_legos_and_i_stab Jul 12 '12 edited Jul 12 '12

A few things you can consider:

  • Rather than declaring CHARS, you can use the string constants.

  • Most python code uses 4 spaces rather than tabs. This is more of a personal style, but if you ever plan to work with other developers, it's a good habit to get in to.

  • Another option for string formatting is to use (again, this is a personal preference. Some people find it easier to read/write):

    print 'getting %s random pics' % HOW_MANY

  • Try using a 3rd party library like Requests to make http requests to imgur.

  • Before you go too far, set up PIP, Virtualenv and Virtualenvwrapper if you haven't already.

  • If you want ideas for next steps, turn it into a little website. Use Vagrant to manage your virtual machine. Install Nginx, supervisor and Gunicorn. Try out Flask or Django.

edit: Also check out PEP8. It's the "style guide" for python. Lots of good info in here to make your code easier to read.

1

u/f0rkbomb Jul 13 '12

this is excellent feedback, thank you. i really like the website idea! i took a gander at the libraries and tools you linked, seems like a great opportunity to learn more :)

1

u/H3g3m0n Jul 13 '12 edited Jul 13 '12

It's worth noting that future versions of Python (starting with 3.3) should be getting their own version of Virtualenv.

I also recall hearing that future versions are going to get some kind packaging system like PIP that downloads the packages from the web (but I can't find a link to that now).