[Tutor] parsing chemical formula

Martijn Faassen M.Faassen@vet.uu.nl
Wed, 31 Mar 1999 10:18:25 +0200


Tim Peters wrote:

> While I normally charge hefty royalties for use of this device, I hereby
> grant lifetime royalty-free licenses to all readers of the Tutor list
> <wink>.

Darn, I never paid royalties, where do I hide!

> You and Martijn went on to have a lot of fun making count-free variations,
> but you neglected to tell the tutorees that anything beyond this is *sick*
> fun.  Sick, sick, sick!  This is the way to do it:

Oh no, Christian, Timbot caught us!

[snip sick sick example costing way too many lines anyway]

> Seriously (and, yes, I'll attach enum.py anyway <wink>), while I generally
> oppose by-hand counting too, you have to weigh it against the alternatives,
> and anything else here is deadly obscure or deadly clumsy.  Not worth it. 

Agreed, still, this is of course an interesting challenge.

> I usually don't bother to count correctly!  In this idiom, if you get the
> count wrong Python will tell you by raising a "unpack of wrong size" error.
> Most of the time you guess right; it's not worth any hassle to avoid the few
> times you don't.

> simple-code-for-our-simple-minds-ly y'rs  - tim
> 
> Here's enum.py.  Tutorees, reminder:  this is sick!  Sick, sick, sick.  Do
> yourself a favor and don't look at it <wink>.
> 
[sick sick sick sick SICK code I don't pretend understanding deleted]

Regards,

Martijn