How to use the exec statement

Alex Martelli aleax at aleax.it
Mon Oct 7 10:25:42 EDT 2002


JB wrote:

> Alex Martelli wrote:
> [...]
> 
> Thx, now everything works fine (but for catching user errors
> that raise exceptions, which I have not implemented yet).

Good to have been of use!

Since you want to catch just about every error the user could
make, you probably want a try/except with a very broad
condition... in fact I fear you need a condition-less except
(always a problem) since the user could raise a string, and
even "except Exception:" won't catch THAT... that's rather
a fragile thing to do (as it may mask any programming error)
but it's hard to think of alternatives.

> The concept of namespaces seems to be rather powerful
> indeed.

Full agreement -- ALMOST powerful enough to tame 'exec'
(not quite, even with the further help given by modules
rexec and Bastion, but almost...).


Alex





More information about the Python-list mailing list