I am new to Python and still learning the tricks.
How can i convert the following code to a single liner, is it possible in Python? There has to be a neat way of doing this.
try: image_file = self.request.files['image_path'] except: image_file = None
KeyErrorfrom adict, then you could usegetexceptis generally not a good idea (unless it's at the end of a chain of named except clauses, and even then you probably want to re-raise the exception after printing a warning or performing some other processing). Always specify the exception(s) that you want to catch.