names

Elliott Chapin echapin at sympatico.ca
Tue Jan 16 17:25:52 EST 2001


Thanks, Alex. A bit more reflection be fore I saw your reply suggests that I
may indeed be better off with nexted dictionaries ending with <whatever>.

--

---------------------------------------------------------------

Elliott Chapin          www3.sympatico.ca/echapin
"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:941k7806l8 at news1.newsguy.com...
> "Elliott Chapin" <echapin at sympatico.ca> wrote in message
> news:trL86.74752$n%.3041493 at news20.bellglobal.com...
> > Thanks, all! I may approach the actual task I have in mind by designing
a
> > class which adds a name to the attributes of its instances.
>
> Excellent idea, and probably also best for the parallel thread
> "determining names of instances" started by Daniel Klein.  You
> will have to pass (e.g.) name='NiceFoo' to the constructor, of
> course, unless you want to have it assign 'random' names...:
>
> def Named:
>     unnamed=0
>     def __init__(self, name=None):
>         if name is None:
>             self.name = "Unnamed_%d" % Named.unnamed
>             Named.unnamed += 1
>         else:
>             self.name = name
>
> You can use this as a mix-in class (inherit your classes from
> it), as long as you remember to call its __init__ appropriately
> from your own __init__ (passing along the name-argument...).
>
>
> Alex
>
>
>
>





More information about the Python-list mailing list