Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3a.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'tree': 0.05; 'messing': 0.09; 'prevents': 0.09; 'proficient': 0.09; 'rows': 0.09; 'scripting': 0.09; 'subject:parsing': 0.09; 'python': 0.11; '-tkc': 0.16; 'csv': 0.16; 'csv,': 0.16; 'fond': 0.16; 'formatting,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'received:174.136': 0.16; 'subsection': 0.16; 'xlrd': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'module': 0.19; 'input': 0.22; 'preferred': 0.22; "i've": 0.25; 'chapter': 0.26; 'this:': 0.26; 'excel': 0.26; 'header:In-Reply-To:1': 0.27; "i'm": 0.30; 'code': 0.31; 'usually': 0.31; 'repair': 0.31; 'anyone': 0.31; 'file': 0.32; 'interface': 0.32; "i'd": 0.34; 'subject:from': 0.34; 'but': 0.35; 'there': 0.35; 'joined': 0.36; 'library.': 0.36; 'charset:us- ascii': 0.36; 'possible': 0.36; 'should': 0.36; 'two': 0.37; 'received:10': 0.37; 'starting': 0.37; 'to:addr:python-list': 0.38; 'anything': 0.39; 'does': 0.39; 'extremely': 0.39; 'structure': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'read': 0.60; 'most': 0.60; 'simple': 0.61; 'first': 0.61; 'you.': 0.62; "you've": 0.63; 'happen': 0.63; 'more': 0.64; 'different': 0.65; 'it!': 0.67; 'believe': 0.68; 'default': 0.69; 'export': 0.74; 'p.s.:': 0.84; 'route': 0.84; 'spreadsheet': 0.84 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1422454314886:2309033204 X-MC-Ingress-Time: 1422454314886 Date: Wed, 28 Jan 2015 08:13:46 -0600 From: Tim Chase To: python-list@python.org Subject: Re: parsing tree from excel sheet In-Reply-To: References: X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com 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: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422455440 news.xs4all.nl 2956 [2001:888:2000:d::a6]:46809 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84759 On 2015-01-28 10:12, alb wrote: > I've a document structure which is extremely simple and represented > on a spreadsheet in the following way (a made up example): > > subsystem | chapter | section | subsection | subsubsec | > A | | | | | > | func0 | | | | > | |interface| | | > | |latency | | | > | |priority | | | > | func1 | | | | > | |interface| | | > | |latency | | | > | |priority | | | > > And I'd like to get a tree like this: > > A > +-------> func0 > | +---> interface > | +---> latency > | \---> priority > \-------> func1 > +---> interface > +---> latency > +---> priority > > I know about the xlrd module to get data from excel If I have to get my code to read Excel files, xlrd is usually my first and only stop. > Does anyone recommend any other path other than scripting through > these two modules? Well, if you export from Excel as CSV, you can use the "csv" module in the standard library. This is actually my preferred route because it prevents people (coughclientscough) from messing up the CSV file with formatting, joined cells, and other weirdnesses that can choke my utilities. > Is there any more suitable module/example/project out there that > would achieve the same result? I don't believe there's anything that will natively do the work for you. Additionally, you'd have to clarify what should happen if two rows in the same section had different sub-trees but the same content/name. Based on your use-case (LaTex export using these as headers) I suspect you'd want a warning so you can repair the input and re-run. But it would be possible to default to either keeping or squashing the duplicates. > p.s.: I'm not extremely proficient in python, actually I'm just > starting with it! Well, you've come to the right place. Most of us are pretty fond of Python here. :-) -tkc