HowCanI: inlined exceptions

Pete Shinners pete at visionart.com
Fri May 26 19:02:37 EDT 2000


Robert Citek wrote:
> Is this something of what you have in mind?
> 
> def catch(expression, errcode=None):
>     try:
>        return eval(expression)
>     except:
>         return errcode

passing the expression in as a string is probably
what i'll resort to, but i'm really hoping there's
a cleaner way to strip out the quotes.

kinda like a #define macro or if python had 
inline-style functions.

how difficult would it be for python to define a new
keyword (or something) to specify a function argument
should be read as a raw string...

>>> def grok_a_string(RAW arg):
...     print 'You Passed:', arg
...
>>> grok_a_string(10+4)
You Passed:10+4


while it wouldn't help me in this problem, it might
also be nice to retreive the raw string of a given
argument

>>> def do_math(math):
...     print raw_argument(math), " = ", math
...
>>> do_math(44/2)
44/2 = 22



anyways, back to my original question. is there a
way i can get an argument not to evaluate when passed
to my function (or class?)
i'm hoping python has a way, and a python-master can
give me some insight. thanks



More information about the Python-list mailing list