[Tutor] parsing chemical formula
Christian Tismer
tismer@appliedbiometrics.com
Tue, 30 Mar 1999 19:43:21 +0200
Sorry, tutor list,
but I could not resist.
I will stop this now. (Ahem)
Martijn Faassen wrote:
>
> Christian Tismer wrote:
>
> > Now, if you must, how 'bout this:
[second try. But watch out...]
> 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!
Now I will him give a final reason to pursue me.
def enum(func):
g = 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
Yeees, this is hefty.
But now watch out what I got for the application:
from spinners.pirx import enum # har har
enum(lambda ONE, TWO, THREE, FOUR, FIVE:1)
# this gives us an enumeration, based from 1. Believe me.
>>> ONE, TWO, THREE, FOUR, FIVE
(1, 2, 3, 4, 5)
Naaah? Oh yeah, now we really have a "useful" lambda example :-)))
ciao - chris.ducked.and.covered.for.the.rest.of....
--
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