Re: try-except syntax

2018-04-06 Thread ElChino
Steven D'Aprano wrote: imp.find_module is deprecated and should not be used in new code. ... try: block except (ImportError, RuntimeError): block Thanks Steven and others who replied. Looks more elegant. By the way, RuntimeError is almost never something you want

Re: try-except syntax

2018-04-05 Thread Steven D'Aprano
On Thu, 05 Apr 2018 23:04:18 +0200, ElChino wrote: > I'm trying to simplify a try-except construct. E.g. how come this: >try: > _x, pathname, _y = imp.find_module (mod, mod_path) > return ("%s" % pathname) imp.find_module is deprecated and should not be used in new code. Putting

Re: try-except syntax

2018-04-05 Thread Gregory Ewing
Ben Bacarisse wrote: Anyway, to coalesce two or more exception handlers, you are probably looking for except (ImportError, RuntimeError): To the OP: Are you sure you really want to mask RuntimeError here? Usually it means something has gone seriously wrong, and is a symptom that shouldn't

Re: try-except syntax

2018-04-05 Thread Ben Bacarisse
ElChino writes: > I'm trying to simplify a try-except construct. E.g. how come > this: > try: > _x, pathname, _y = imp.find_module (mod, mod_path) > return ("%s" % pathname) > except ImportError: > pass > except RuntimeError: > pass > return ("") > >

Re: try-except syntax

2018-04-05 Thread Ian Kelly
On Thu, Apr 5, 2018 at 3:04 PM, ElChino wrote: > I'm trying to simplify a try-except construct. E.g. how come > this: > try: > _x, pathname, _y = imp.find_module (mod, mod_path) > return ("%s" % pathname) > except ImportError: > pass > except RuntimeError: >

Re: try-except syntax

2018-04-05 Thread Rob Gaddi
On 04/05/2018 02:04 PM, ElChino wrote: I'm trying to simplify a try-except construct. E.g. how come this:   try:     _x, pathname, _y = imp.find_module (mod, mod_path)     return ("%s" % pathname)   except ImportError:     pass   except RuntimeError:     pass     return ("") Cannot be

try-except syntax

2018-04-05 Thread ElChino
I'm trying to simplify a try-except construct. E.g. how come this: try: _x, pathname, _y = imp.find_module (mod, mod_path) return ("%s" % pathname) except ImportError: pass except RuntimeError: pass return ("") Cannot be simplified into this: try: _x, pathname, _y