[Tutor] the class struggle

Kirby Urner urnerk@qwest.net
Fri, 30 Nov 2001 18:40:37 -0800

>myList = ['Marx', 'Engels', 'Lenin', 'Mao']
>for x in myList:
>   execString = x + ' = Struggle(soviet, "' + x + '")'
>   exec(execString)
>   evalCommunist = x + '.Communist'
>   evalSoviet = x + '.Soviet'
>   if eval(evalCommunist):
>     print x, 'was a known Communist.'
>   if eval(evalSoviet):
>     print x, 'was a Soviet leader.'
>print "rob0 is winning the struggle to understand Python classes."

Although these exec-intensive code segments are fun to
write, I think they obscure your demonstration.  If the
point is to show what your Struggle class is doing, it'd
be best to not automate all the keystrokes here (lots
of extraneous overhead), and simply quote some
straightforward shell, e.g.

  >>> Marx = Struggle(['Lenin', 'Trotsky', 'Stalin'],'Marx')
  >>> if Marx.Communist:
         print 'Marx', 'was a known Communist'

  "Marx was a known Communist"

Queuing up a bunch of variable names in a list and
looping through an exec to assign them, and then
evaluate their properties, might make sense in some
bigger program (might), but for sharing purposes (i.e.
making your meanings clear), all this exec stuff seems
unnecessarily obfuscatory.

Just for future reference, in case you're trying
to present another case study.

>That did it!! Thank you all for turning the light on. :)

In any case, you've achieved your goal, and that's
the important thing.