What do you use as symbols for Python ?

Daniel Evers daniel.evers at rwth-aachen.de
Sat Nov 12 16:52:57 CET 2005


Peter Otten wrote:
> 
> You should ditch what follows and instead add just
> 
>           def __iter__(self):
>               return  iter(self.__keys)

Mhh. I should start learning the builtins ... :)

> To see the problem with your original code (an object serving as its own
> iterator) try the following example:
> 
>     friends = Enum("Eric", "Kyle", "Stan", "Kenny")
>     if "Kyle" in friends:
>         print "Hi Kyle"
>     print "My friends:", ", ".join(friends)
> 
> Only Stan and Kenny show up in the last print statement because the
> containment test did not iterate over all friends.

Never would have thought of this... Makes it even easier.

> Also, Type.__name seems redundant. Just
> 
> class Type(str): pass
> 
> should do the job.

Right, works just fine. I'm not used to types, meanwhile I replaced
Type(str) by a simple class Type, works as well.

Thanks a lot, I was starting to integrate this solution in my code, now I
can fix it before it's even used :)

Daniel



More information about the Python-list mailing list