[Tutor] Unix commands python
Kooser, Ara S
askoose at sandia.gov
Tue Apr 27 13:30:47 EDT 2004
Thank you very much. I will try that out.
Ara
-----Original Message-----
From: Andrew Fant [mailto:andrew.fant at tufts.edu]
Sent: Tuesday, April 27, 2004 11:29 AM
To: 'tutor at python.org'
Cc: Kooser, Ara S
Subject: Re: [Tutor] Unix commands python
Ara,
It is possible to use unix commands from within python, but I would
suggest that you would get further in this case by using the split method
in the strings module.
If you are reading lines from a file into a string called 'foo', you can
write something like:
splitfoo=foo.split()
and then reference each column as splitfoo[x] where x is some number
between zero and the number of fields.
I've been doing the same sort of thing for parsing performance data to pass
into our web-graphing software, and it's much faster to chop it up in
python than to spawn child processes to do it in awk.
HTH
Andy
--On Tuesday, April 27, 2004 11:01:54 -0600 "Kooser, Ara S"
<askoose at sandia.gov> wrote:
>
> Hello all,
>
> I am new at python and I am working on a file conversion program.
> Thank you for all the advice that got me to this point. Is it possible
> to invoke unix commands in python, such as awk or cut? I am trying to
> cut some columns of text and then transform one of those columns with
> user input. Thanks.
>
> Ara
More information about the Tutor
mailing list