Re: Handling import errors

2011-06-22 Thread Guillaume Martel-Genest
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

Re: Handling import errors

2011-06-21 Thread Chris Rebert
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

Re: Handling import errors

2011-06-21 Thread Mel
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

Re: Handling import errors

2011-06-21 Thread Miki Tebeka
> 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

Re: Handling import errors

2011-06-21 Thread Tim Johnson
* 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:

Handling import errors

2011-06-21 Thread Guillaume Martel-Genest
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

Handling import errors

2011-06-21 Thread Guillaume Martel-Genest
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