Re: [Tutor] text processing lines variable content

2019-02-07 Thread ingo janssen
On 07/02/2019 18:06, Peter Otten wrote: Sorry, I don't understand the question. after a quick look not unlike what you propose but I have to investigate further, lengths of chunks are known or can be found (sketchy): order=

Re: [Tutor] text processing lines variable content

2019-02-07 Thread Peter Otten
ingo janssen wrote: > > > On 07/02/2019 11:08, Peter Otten wrote: >> replace the sequence of tests with dictionary lookups > > updated the gist a few times, now I could pre calculate the slices to be > taken per line, but will there be much gain compared to the copping from > the left side of

Re: [Tutor] text processing lines variable content

2019-02-07 Thread ingo janssen
On 07/02/2019 11:08, Peter Otten wrote: replace the sequence of tests with dictionary lookups updated the gist a few times, now I could pre calculate the slices to be taken per line, but will there be much gain compared to the copping from the left side of the list? ingo

Re: [Tutor] text processing lines variable content

2019-02-07 Thread ingo janssen
On 07/02/2019 11:08, Peter Otten wrote: Personally I would avoid the NameError and start with empty lists. If you manage to wrap all branches into functions with the same signature you can replace the sequence of tests with dictionary lookups. Just before I saw your post I put my current

Re: [Tutor] text processing lines variable content

2019-02-07 Thread ingo janssen
On 07/02/2019 10:40, Alan Gauld via Tutor wrote: Just saves a little typing is all. Sensei, be lazy, I will study current state of code is at https://gist.github.com/ingoogni/e99c561f23777e59a5aa6b4ef5fe37c8 ingo ___ Tutor maillist -

Re: [Tutor] text processing lines variable content

2019-02-07 Thread Peter Otten
ingo janssen wrote: > > On 07/02/2019 09:29, Peter Otten wrote: >> Where will you get the order from? > > Peter, > > the order comes from the command line. Then my one-function-per-format approach won't work. > I intend to call the python > program with the same command line options as the

Re: [Tutor] text processing lines variable content

2019-02-07 Thread Alan Gauld via Tutor
On 07/02/2019 08:58, ingo janssen wrote: >try: > lbl = f_label(label) >except NameError as e: > lbl = f_number(label) > label=[lbl] Just a minor point but since you aren't doing anything with the error you don't need the 'as e' bit at the end of each

Re: [Tutor] text processing lines variable content

2019-02-07 Thread ingo janssen
On 07/02/2019 09:58, ingo janssen wrote: On 07/02/2019 09:29, Peter Otten wrote: Where will you get the order from? Ahrg, that should have been: #all output formatting options order = "%i %q %r %w %p %P %o %m %g %E %s %e %F %a %A %f %t %l %n %v %c %C" order =

Re: [Tutor] text processing lines variable content

2019-02-07 Thread ingo janssen
On 07/02/2019 09:29, Peter Otten wrote: Where will you get the order from? Peter, the order comes from the command line. I intend to call the python program with the same command line options as the Voro++ program. Make the python program call the Voro++ and process its output. one

Re: [Tutor] text processing lines variable content

2019-02-07 Thread Peter Otten
ingo janssen wrote: > depending on how the input file is created data packet a can be in an > other position for every line. > figured out how to do it though > > order=[a,b,e,d...] > for i in lines: >i=i.split(" ") > for j in order: >if j = a: > use function for processing data

Re: [Tutor] text processing lines variable content

2019-02-06 Thread ingo janssen
On 06/02/2019 21:45, Mark Lawrence wrote: So what, you still don't need to chop the front from the list, just process the data. just slice I'd like to adapt the order in that the functions are applied, but how? I suspect that you're trying to over complicate things, what's wrong

Re: [Tutor] text processing lines variable content

2019-02-06 Thread Mark Lawrence
On 06/02/2019 18:51, ingo janssen wrote: On 06/02/2019 19:07, Mark Lawrence wrote: That's going to a lot of work slicing and dicing the input lists. Perhaps a chunked recipe like this https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.chunked would be better. The

Re: [Tutor] text processing lines variable content

2019-02-06 Thread ingo janssen
On 06/02/2019 19:07, Mark Lawrence wrote: That's going to a lot of work slicing and dicing the input lists. Perhaps a chunked recipe like this https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.chunked would be better. The length of the text chunks varies from a single

Re: [Tutor] text processing lines variable content

2019-02-06 Thread Mark Lawrence
On 06/02/2019 16:33, ingo janssen wrote: For parsing the out put of the Voro++ program and writing the data to a POV-Ray include file I created a bunch of functions. def pop_left_slice(inputlist, length):   outputlist = inputlist[0:length]   del inputlist[:length]   return outputlist

[Tutor] text processing lines variable content

2019-02-06 Thread ingo janssen
For parsing the out put of the Voro++ program and writing the data to a POV-Ray include file I created a bunch of functions. def pop_left_slice(inputlist, length): outputlist = inputlist[0:length] del inputlist[:length] return outputlist this is used by every function to chop of the