Re: parsing tree from excel sheet

2015-02-01 Thread Peter Otten
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 =

Re: parsing tree from excel sheet

2015-01-31 Thread Peter Otten
alb wrote: def read_tree(rows, levelnames): root = Node(#ROOT, #ROOT) old_level = 0 stack = [root] for i, row in enumerate(rows, 1): I'm not quite sure I understand what is the stack for. As of now is a list whose only element is root. The stack is used to emulate

Re: parsing tree from excel sheet

2015-01-31 Thread Peter Otten
alb wrote: def read_tree(rows, levelnames): root = Node(#ROOT, #ROOT) old_level = 0 stack = [root] for i, row in enumerate(rows, 1): I'm not quite sure I understand what is the stack for. As of now is a list whose only element is root. The stack is used to emulate

Re: parsing tree from excel sheet

2015-01-31 Thread alb
Hi Peter, Peter Otten __pete...@web.de wrote: [] Let's start with the simplest: Peter Otten __pete...@web.de wrote: def show2(self): yield str(self) for child in self.children: yield from child.show2() [] Given a tree A -- A1 A2 -- A21

Re: parsing tree from excel sheet

2015-01-30 Thread Peter Otten
alb wrote: Hi Peter, I'll try to comment the code below to verify if I understood it correctly or missing some major parts. Comments are just below code with the intent to let you read the code first and my understanding afterwards. Let's start with the simplest: Peter Otten

Re: parsing tree from excel sheet

2015-01-30 Thread Peter Otten
Peter Otten wrote: [A, A1, A21, A22] Finally the append_nodes(A3, nodes) will append A3 and then return because it has no children, and we end up with nodes = [A, A1, A21, A22, A3] Yay, proofreading! Both lists should contain A2: [A, A1, A2, A21, A22] nodes = [A, A1, A2, A21, A22, A3]

Re: parsing tree from excel sheet

2015-01-30 Thread alb
Hi Peter, I'll try to comment the code below to verify if I understood it correctly or missing some major parts. Comments are just below code with the intent to let you read the code first and my understanding afterwards. Peter Otten __pete...@web.de wrote: [] $ cat parse_column_tree.py

Re: parsing tree from excel sheet

2015-01-29 Thread alb
Hi Peter, Peter Otten __pete...@web.de wrote: [] def show2(self): yield str(self) for child in self.children: yield from child.show2() here is what I get: SyntaxError: invalid syntax debian@debian:example$ python3 export_latex.py doctree.csv File

Re: parsing tree from excel sheet

2015-01-29 Thread Chris Kaynor
On Thu, Jan 29, 2015 at 1:59 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: On 29/01/2015 21:32, alb wrote: Hi MRAB, MRAB pyt...@mrabarnett.plus.com wrote: [] SyntaxError: invalid syntax debian@debian:example$ python3 export_latex.py doctree.csv File export_latex.py, line 36

Re: parsing tree from excel sheet

2015-01-29 Thread alb
Hi MRAB, MRAB pyt...@mrabarnett.plus.com wrote: [] SyntaxError: invalid syntax debian@debian:example$ python3 export_latex.py doctree.csv File export_latex.py, line 36 yield from child.show2() ^ SyntaxError: invalid syntax and I've tried with both python and python3

Re: parsing tree from excel sheet

2015-01-29 Thread alb
Hi Tim, Tim Chase python.l...@tim.thechases.com wrote: [] 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. It provides quite a good interface to manipulating excel files and I find it pretty easy

Re: parsing tree from excel sheet

2015-01-29 Thread Mark Lawrence
On 29/01/2015 21:32, alb wrote: Hi MRAB, MRAB pyt...@mrabarnett.plus.com wrote: [] SyntaxError: invalid syntax debian@debian:example$ python3 export_latex.py doctree.csv File export_latex.py, line 36 yield from child.show2() ^ SyntaxError: invalid syntax and I've tried

Re: parsing tree from excel sheet

2015-01-29 Thread MRAB
On 2015-01-29 21:02, alb wrote: Hi Peter, Peter Otten __pete...@web.de wrote: [] def show2(self): yield str(self) for child in self.children: yield from child.show2() here is what I get: SyntaxError: invalid syntax debian@debian:example$ python3 export_latex.py

Re: parsing tree from excel sheet

2015-01-29 Thread Chris Angelico
On Fri, Jan 30, 2015 at 8:32 AM, alb al.bas...@gmail.com wrote: Ok, that either means I need to upgrade to 3.3 or need to modify the snippet to a suitable syntax that would work with other versions. You could replace yield from child.show2() with: for val in child.show2(): yield val and it

Re: parsing tree from excel sheet

2015-01-28 Thread Tim Chase
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

Re: parsing tree from excel sheet

2015-01-28 Thread Peter Otten
alb wrote: Hi everyone, 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 |

Re: parsing tree from excel sheet

2015-01-28 Thread alb
Hi Peter, Peter Otten __pete...@web.de wrote: [] You can save the excel sheet as csv so that you an use the csv module which may be easier to use than xlrd. The rest should be doable by hand. Here's what I hacked together: $ cat parse_column_tree.py import csv def column_index(row):

parsing tree from excel sheet

2015-01-28 Thread alb
Hi everyone, 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 | |