Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #84992

Re: parsing tree from excel sheet

Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.05; 'intermediate': 0.07; 'nested': 0.07; 'string': 0.09; 'generators': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:parsing': 0.09; 'translate': 0.10; 'api': 0.11; 'def': 0.12; 'language,': 0.12; 'mostly': 0.14; "'foobar'": 0.16; 'accepts': 0.16; 'innermost': 0.16; 'levels,': 0.16; 'operates': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'simpler': 0.24; "i've": 0.25; 'options': 0.25; 'skip:" 30': 0.26; 'pass': 0.26; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'gives': 0.31; 'seemingly': 0.31; 'file': 0.32; 'text': 0.33; 'subject:from': 0.34; 'common': 0.35; 'but': 0.35; 'advertised': 0.36; 'yield': 0.36; 'being': 0.38; 'initially': 0.38; 'question,': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'most': 0.60; 'simply': 0.61; 'different': 0.65; 'here': 0.66; 'direct': 0.67; 'reverse': 0.68; 'obvious': 0.74; 'clip': 0.84; 'more:': 0.84; 'substrings': 0.84; 'approach.': 0.91; 'wait,': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: parsing tree from excel sheet
Date Sun, 01 Feb 2015 11:11:31 +0100
Organization None
References <cirqviF15qtU1@mid.individual.net> <mailman.18217.1422454096.18130.python-list@python.org> <cj1kt9Fi3e0U1@mid.individual.net> <mailman.18314.1422637907.18130.python-list@python.org> <cj547rFfl2sU1@mid.individual.net>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd9e61.dip0.t-ipconnect.de
User-Agent KNode/4.13.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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18356.1422785505.18130.python-list@python.org> (permalink)
Lines 74
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1422785505 news.xs4all.nl 2926 [2001:888:2000:d::a6]:48530
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:84992

Show key headers only | View raw


alb wrote:

>> But wait, "".join() only accepts strings so let's change
>>
>>yield [node]
>>
>> to
>>yield [node.name] # str(node) would also work
> 
> Again my question, why not simply yield node.name?

I've been conditioned to build a string from many substrings like so

>>> parts = ["foo", "bar", "baz"] 
>>> text = "".join(parts)
>>> text
'foobarbaz'

instead of

>>> text = ""
>>> for part in parts:
...     text += part
... 
>>> text
'foobarbaz'

mostly because ""join(...) was initially advertised as being faster than +=.

For nested generators or functions this translates into

>>> def outer_list():
...     return ["foo"] + inner_list()
... 
>>> def inner_list():
...     return ["bar"]
... 
>>> "".join(outer_list())
'foobar'

instead of the obvious

>>> def outer():
...     return "foo" + inner()
... 
>>> def inner():
...     return "bar"
... 
>>> outer()
'foobar'

Here the list-based approach may build many intermediate throwaway-lists, so 
it's most likely less efficient than direct string concatenation. In return 
it gives you flexibility:

>>> "/".join(outer_list())
'foo/bar'
>>> "-->".join(outer_list())
'foo-->bar'

You'd have to pass the separator as an argument to outer/inner() to achieve 
this with the seemingly simpler approach. But there's more:

You can reverse the order, 

>>> ":".join(reversed(outer_list()))
'bar:foo'

treat the innermost string differently, translate each part into a different 
language, clip common levels, etc. Your options are unlimited.

I never understood why the file system API operates on a single string...

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

parsing tree from excel sheet al.basili@gmail.com (alb) - 2015-01-28 10:12 +0000
  Re: parsing tree from excel sheet Peter Otten <__peter__@web.de> - 2015-01-28 15:08 +0100
    Re: parsing tree from excel sheet al.basili@gmail.com (alb) - 2015-01-28 14:27 +0000
    Re: parsing tree from excel sheet al.basili@gmail.com (alb) - 2015-01-29 21:02 +0000
      Re: parsing tree from excel sheet MRAB <python@mrabarnett.plus.com> - 2015-01-29 21:16 +0000
        Re: parsing tree from excel sheet al.basili@gmail.com (alb) - 2015-01-29 21:32 +0000
          Re: parsing tree from excel sheet Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-29 21:59 +0000
          Re: parsing tree from excel sheet Chris Kaynor <ckaynor@zindagigames.com> - 2015-01-29 14:30 -0800
          Re: parsing tree from excel sheet Chris Angelico <rosuav@gmail.com> - 2015-01-30 10:46 +1100
    Re: parsing tree from excel sheet al.basili@gmail.com (alb) - 2015-01-30 15:05 +0000
      Re: parsing tree from excel sheet Peter Otten <__peter__@web.de> - 2015-01-30 18:11 +0100
        Re: parsing tree from excel sheet al.basili@gmail.com (alb) - 2015-01-31 22:45 +0000
          Re: parsing tree from excel sheet Peter Otten <__peter__@web.de> - 2015-02-01 11:11 +0100
      Re: parsing tree from excel sheet Peter Otten <__peter__@web.de> - 2015-01-30 18:24 +0100
      Re: parsing tree from excel sheet Peter Otten <__peter__@web.de> - 2015-01-31 10:07 +0100
      Re: parsing tree from excel sheet Peter Otten <__peter__@web.de> - 2015-01-31 10:07 +0100
  Re: parsing tree from excel sheet Tim Chase <python.list@tim.thechases.com> - 2015-01-28 08:13 -0600
    Re: parsing tree from excel sheet al.basili@gmail.com (alb) - 2015-01-29 21:22 +0000

csiph-web