View Single Post
Old 06-09-2014, 03:17 PM   #27
roger64
Wizard
roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.roger64 ought to be getting tired of karma fortunes by now.
 
Posts: 2,608
Karma: 3000161
Join Date: Jan 2009
Device: Kindle PW3 (wifi)
@DiapDealer

Crossing the fingers, here is pingouin2 which takes into account your previous remark.

Code:
#!/usr/bin/python

import sys, re

conv=2.37106301584
unit=re.compile('(:\s*)(-?[\d.]+)(cm)?(;|})')
with open(sys.argv[1],'r') as f, open(sys.argv[2],'w') as g :

   fic=f.read()

   while True :
      k=unit.search(fic)
      if(k) :
         g.write(fic[:k.start(1)])
         g.write(k.group(1))
         val=k.group(2)
         unite=k.group(3)
         if unite=='cm' :
            val="%.2f"%(conv*float(k.group(2)))
            unite='em'
         else : unite=''
         g.write(val+unite)
         g.write(k.group(4))
         fic=fic[k.end(4):]
      else :
         g.write(fic)
         break
With the new release, I will make another round of testing involving some other people. I suppose this release will also be working for both Python 2.x and 3.x. If you take Kovid Goyal's advice, please provide some comments as this is way above my head.

Last edited by roger64; 06-09-2014 at 03:26 PM.
roger64 is offline   Reply With Quote