I did not think about using a global variable, and the top-level
try...except solution is interesting. After further thinking, I have
to reformulate my initial question:
How do I manage to run code before my imports?
For example, I want to make sure that I can use the logging module in
the case a
On Tue, Jun 21, 2011 at 1:51 PM, Guillaume Martel-Genest
wrote:
> 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 w
Guillaume Martel-Genest wrote:
> 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).
Actually, you can if you declare them glo
> try:
> import foo
> except ImportError:
> logging.error('could not import foo')
> sys.exit(1)
Why not just let the exception terminate the program? It will have even more
information about the problem that caused foo not to load.
--
http://mail.python.org/mailman/listinfo/python-lis
* Guillaume Martel-Genest [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:
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:
try:
import foo
except ImportError:
logging
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:
try:
--
http://mail.python.org/mailman/listinfo/py