[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: Handling import errors
From: Tim Johnson <tim () johnsons-web ! com>
Date: 2011-06-21 21:10:16
Message-ID: 20110621211016.GR1971 () johnsons-web ! com
[Download RAW message or body]
* Guillaume Martel-Genest <guillaumemg@gmail.com> [110621 12:53]:
> What is the pythonic way to handle imports error? What is bugging me
> is that the imports can't be inside a function (because I use them in
> different places in the script and thus they have to be in the global
> scope). I would write something like:
Suppose you do something like this:
try :
mod = __import__('mymodulename')
except ImportError:
pass ## replace with error handling here
so `mod' is global if you execute the above code as top-level,
*but* you can also pass `mod' as an argument like any other
variable, as far as I know and far as I have done.
--
Tim
tim at johnsons-web dot com or akwebsoft dot com
http://www.akwebsoft.com
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic