[Tutor] parsing chemical formula

Christian Tismer tismer@appliedbiometrics.com
Tue, 30 Mar 1999 20:04:35 +0200


Christian Tismer wrote:
> 
> Sorry, tutor list,
> but I could not resist.
> I will stop this now. (Ahem)

Last refinement: To make an import of enum
possible, I have to obtain the globals from the lambda:

# in somewhere.py
def enum(func):
    g = func.func_globals ; code = func.func_code
    base = apply(func, (0,)*code.co_argcount) or 0
    for i in range(code.co_argcount):
        g[code.co_varnames[i]] = i+base

# Now I can do

from somewhere import enum

enum(lambda ONE, TWO, THREE, FOUR, FIVE:1)

ciao - chris

-- 
Christian Tismer             :^)   <mailto:tismer@appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101   :    *Starship* http://starship.python.net
10553 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home