Message61631
Guido's document "Unifying types and classes in Python 2.2" (descrintro)
contains a confusing example for metaclass newbies.
<http://www.python.org/download/releases/2.2.3/descrintro/#metaclass_examples>
The example in question is autoprop, which uses the variable "name" in
three different contexts. First, it is the name of the class being
created. Second, it is used in a for loop to denote the keys of the
class dict. And thirdly, it is used to denote substrings of a subset of
those keys.
Upon my first encounter with the example, I found myself staring at the
getattr and setattr lines in disbelief. I associated "name" as the
parameter given to the __init__ function.
I'd propose changing the first for-loop name to "member" or similar
and the second to "propname" or "prop".
Furthermore, a modern version of the same example could use sets and set
comprehensions instead of dict.keys():
props = {member[5:] for member in dict if member.startswith...} |
|
| Date |
User |
Action |
Args |
| 2008-01-24 13:35:47 | arsatiki | set | spambayes_score: 0.0500188 -> 0.0500188 recipients:
+ arsatiki |
| 2008-01-24 13:35:47 | arsatiki | set | spambayes_score: 0.0500188 -> 0.0500188 messageid: <1201181747.66.0.31684496906.issue1921@psf.upfronthosting.co.za> |
| 2008-01-24 13:35:46 | arsatiki | link | issue1921 messages |
| 2008-01-24 13:35:46 | arsatiki | create | |
|