Michele Petrazzo 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 code work?
>
> My code:
>
> STR
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
sim
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
--
http://mail.python.org
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
--
http://mail.python.org/mailman/l
On May 29, 7:21 am, Michele Petrazzo
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 solution to convert or make this co
On May 29, 7:21 am, Michele Petrazzo
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 solution to convert or make this co
On May 29, 9:55 am, Michele Petrazzo
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 env
> > t
On Fri, May 29, 2009 at 11:55 AM, Michele Petrazzo
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"
> error message. This means that t
On 5/29/2009 8:55 AM Michele Petrazzo said...
Aaron Brady wrote:
Then the formatted exception will be available in 'err'. Do you want
the exception-handling to be part of the function you are entering
into 'env'?
My goal is to execute a function received from a third-part, so I cannot
modi
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 env
try:
env["a_funct"]()
except ZeroDivisionError:
import traceback
err = traceback.for
On May 29, 8:21 am, Michele Petrazzo
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 solution to convert or make this co
11 matches
Mail list logo