Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:help': 0.07; 'python': 0.09; 'fork': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; '2.7': 0.13; '"normal"': 0.16; 'dog': 0.16; 'fruit': 0.16; 'key):': 0.16; 'no-nonsense': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'self[key]': 0.16; 'tempted': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'header:User-Agent:1': 0.26; 'wondering': 0.26; 'header:X -Complaints-To:1': 0.28; '>>>>': 0.29; 'cat': 0.29; 'writes:': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'profit': 0.33; 'to:addr :python-list': 0.33; 'self': 0.34; 'list': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'further': 0.61; 'skip:n 10': 0.63; 'more': 0.63; 'fun': 0.64; 'gave': 0.65; 'subject:Data': 0.65; 'leo': 0.84; 'now...': 0.84; 'otten': 0.84; 'pear': 0.84; 'do:': 0.91; 'subject:urgent': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Data Tree urgent help!!!!!! Date: Wed, 20 Feb 2013 11:46:33 +0100 Organization: None References: <4abbe91f-a57e-47de-9cf3-5b9574201c83@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084ab9c.dip.t-dialin.net User-Agent: KNode/4.7.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361357186 news.xs4all.nl 6978 [2001:888:2000:d::a6]:52466 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39338 Leo Breebaart wrote: > Peter Otten <__peter__@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...