[Tutor] parsing chemical formula

Martijn Faassen M.Faassen@vet.uu.nl
Tue, 30 Mar 1999 19:08:36 +0200


Christian Tismer wrote:
 
> Now, if you must, how 'bout this:
> 
> >>> def make_enum(func, base):
> ...     g = globals()
> ...     for i in range(func.func_code.co_argcount):
> ...         g[func.func_code.co_varnames[i]] = i+base
> ...     del g[func.__name__]
> ...
> >>> # after this, you can fake an enum like this
> >>> def enum(ONE, TWO, THREE) : pass
> >>> # and you activate it so:
> >>> make_enum(enum, 1)
> >>> # here we are:
> >>> ONE, TWO, THREE
> (1, 2, 3)
> >>>

Hm, this is too many lines [whine, nag, never-pleased-ly yours]. As
kludge trickery though, it's way cool!
 
> I think I have to duck and cover if Timbot watches me :-)

Indeed, Timbot is sure to catch us at this soon!

Martijn