[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] rearranging data files



Ha! Perl 1, Python 0....

(Sorry, couldn't resist.)

ap

----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu


On Fri, 7 Jun 2002, Joerg Johannes wrote:

> Am Freitag, 7. Juni 2002 01:21 schrieben Sie:
> Thank you, Matias, for your reply. I tried out your script, but I get the 
> following error when using it:
> 
> jorg@blaubaer:~/test$ ./datenumkehr.py jo-001.asc 
> Traceback (most recent call last):
>   File "./datenumkehr.py", line 14, in ?
>     if float(numbers[i])>=0:
> ValueError: empty string for float()
> 
> As I never learned python (nor an other scripting language), I don't know 
> what that means, nor how to fix it.
> Any idea?
> 
> joerg
> >
> > I have written a little python script to do it. Hope it works for you. :-)
> >
> > #!/usr/bin/env python
> > import re,sys,string
> >
> > if len(sys.argv) != 2:
> >     print "Usage: %s infile" %(sys.argv[0])
> >     sys.exit()
> > infile = string.replace(open(sys.argv[1]).read(),"\n"," ")
> > pattern = re.compile(r"(?:(.+?[ ]) *)",re.DOTALL)
> > numbers = pattern.findall(infile)
> > outp = ""
> > for i in range(len(numbers)):
> >     if (i%2):
> >         outp+='\t'
> >     if float(numbers[i])>=0:
> >         outp+=' '
> >     outp+=numbers[i]+(' '*(10-len(numbers[i])))
> >     if float(numbers[i])>=0: outp+=' '
> >     if (i%2):
> >         outp+='\n'
> > print outp
> > - --
> > Matias Hermanrud Fjeld
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
> 
> 


-- 
To UNSUBSCRIBE, email to debian-user-request@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org



Reply to: