Arg decoding with a template?

Chui Tey teyc at bigfoot.com
Fri Aug 3 00:12:59 EDT 2001


How about exploiting the python parser ?

>>> args="arg1, arg2, arg3='world'"
>>> s='def f(%s): pass' % args
>>> exec(s)
>>> dir(f.func_code)
['co_argcount', 'co_code', 'co_consts', 'co_filename', 'co_firstlineno',
'co_fla
gs', 'co_lnotab', 'co_name', 'co_names', 'co_nlocals', 'co_stacksize',
'co_varna
mes']
>>> print f.func_code.co_argcount
3
>>> print f.func_code.co_varnames
('arg1', 'arg2', 'arg3')
>>> print f.func_defaults
('world',)

Chui

Dale Strickland-Clark <dale at riverhall.NOSPAMco.uk> wrote in message
news:ljidmtouqj6som2t9ecagbkj95c53kjaeh at 4ax.com...
> Is there a class that simplifies high-level argument decoding under the
control of a template?
>
> Such a class would take a string as a template and the arg list and return
another list populated
> with keys, values and switches taken from the args.
>
> I've spent the last hour going through the global module list. If it's
there, its got a daft name!
> --
> Dale Strickland-Clark
> Riverhall Systems Ltd





More information about the Python-list mailing list