Re: try except inside exec

2009-05-31 Thread Michele Petrazzo
Emile van Sebille wrote: Write the string out to a .py file and import it? I don't think that it's possible. I want to create an env that are accessible only from that peace of code and not from the code that execute the third-party one. Emile Michele --

Re: try except inside exec

2009-05-31 Thread Michele Petrazzo
David Stanek wrote: Is the thirdparty function the entire STR or just the a_funct part? Just the a_funct. Only for try and for see if it's possible to catch all the (possible) exception(s), I add the try/except clause that include the a_funct external code. Michele --

Re: try except inside exec

2009-05-31 Thread Michele Petrazzo
Aaron Brady wrote: Exceptions are only caught when raised in a 'try' statement. If you don't raise the exception in a try statement, it won't be caught. The function you posted will raise an exception. If you are making the call yourself, that is, if only the definition is foreign, then

Re: try except inside exec

2009-05-31 Thread alex23
Michele Petrazzo michele.petra...@remove_me_unipex.it wrote: I want to execute a python code inside a string and so I use the exec statement. The strange thing is that the try/except couple don't catch the exception and so it return to the main code. Is there a solution to convert or make this

Re: try except inside exec

2009-05-29 Thread Aaron Brady
On May 29, 8:21 am, Michele Petrazzo michele.petra...@remove_me_unipex.it wrote: Hi all, I want to execute a python code inside a string and so I use the exec statement. The strange thing is that the try/except couple don't catch the exception and so it return to the main code. Is there a

Re: try except inside exec

2009-05-29 Thread David Stanek
On Fri, May 29, 2009 at 11:55 AM, Michele Petrazzo michele.petra...@remove_me_unipex.it wrote: My goal is to execute a function received from a third-part, so I cannot modify as you made in your first piece of code. I want a clean exception with the real line code/tb so I can show a real

Re: try except inside exec

2009-05-29 Thread Aaron Brady
On May 29, 9:55 am, Michele Petrazzo michele.petra...@remove_me_unipex.it wrote: Aaron Brady wrote: STR = class Globals:    err = 0 def a_funct():    try:       1/0    except ZeroDivisionError:       import traceback       Globals.err = traceback.format_exc() exec STR in

Re: try except inside exec

2009-05-29 Thread Carl Banks
On May 29, 7:21 am, Michele Petrazzo michele.petra...@remove_me_unipex.it wrote: Hi all, I want to execute a python code inside a string and so I use the exec statement. The strange thing is that the try/except couple don't catch the exception and so it return to the main code. Is there a

Re: try except inside exec

2009-05-29 Thread Carl Banks
On May 29, 7:21 am, Michele Petrazzo michele.petra...@remove_me_unipex.it wrote: Hi all, I want to execute a python code inside a string and so I use the exec statement. The strange thing is that the try/except couple don't catch the exception and so it return to the main code. Is there a