Leo Breebaart wrote: > Peter Otten <__pete...@web.de> writes: > >> >>> class Name(str): >> ... def __repr__(self): >> ... return self >> ... >> >>> apple, pear, dog, cat, fork, spoon = map(Name, "apple pear dog cat >> >>> fork spoon".split()) > > Is there any reason why you introduced the Name class? In Python > 2.7 this works equally well if I just do: > >>>> apple, pear, dog, cat, fork, spoon = map(str, "apple pear dog cat fork >>>> spoon".split()) > > So I was wondering why you used Name.
It was more for fun than profit ;) The OP gave [apple, dog, fork] in his examples, and the "normal" no-nonsense approach using a list of strings would produce ['apple', 'dog', 'fork'] I was tempted to carry this even further with >>> class Name(str): ... def __repr__(self): return self ... >>> class Namespace(dict): ... def __missing__(self, key): ... self[key] = result = Name(key) ... return result ... >>> fruit, pets, cutlery = eval("[apple, pear], [dog, cat], [fork, spoon]", Namespace()) >>> fruit [apple, pear] but resisted until now... -- http://mail.python.org/mailman/listinfo/python-list