[Tutor] text processing lines variable content

ingo janssen ingoogni at gmail.com
Thu Feb 7 03:58:48 EST 2019


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 command line option contains a string for formatting the output. 
That is what I use for order.

#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.findall("%[a-z]",order,re.M|re.I)
for i, line in enumerate(open("vorodat.vol",'r')):
   points = i
   line = line.strip()
   line = line.split(" ")
   for action in order:
     if action == "%i":
       try:
         lbl = f_label(label)
       except NameError as e:
          lbl = f_number(label)
          label=[lbl]
     elif action == "%q":
       try:
         f_vector(point)
       except NameError as e:
           point = [f_vector(point)]
     elif action == "%r":
       try:
         f_value(radius)
       except NameError as e:
         radius=[f_value(radius)]
etc.

order is important as %w tells me how long %p, %P and %o will be. This 
varies per line.

I'll look into what you wrote,

thanks,

ingo


More information about the Tutor mailing list