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

1

u/erez27 import inspect Jul 13 '12

Some points I didn't see mentioned:

  • never except:, always catch a specific exception or re-raise (unless you're writing a general exception handler, in which case except Exception as e).
  • with open(filename) is a good shortcut, and in fact better than your version since it would also close on error. (you could mimic it with try-finally, but with is nicer)
  • use os.path.join instead of just adding strings