how to modify row content of file in python?
simon.hibbs at gmail.com
Tue Oct 27 14:12:58 CET 2009
On 27 Oct, 07:55, holmes86 <holme... at gmail.com> wrote:
> Is there function of modify row content in python? just like 'sed' in
You would do something like this, which acepts a CSV file from stdin
and sends the first column to stdout (prints it), which you could
redirect to a file or pipe to another command.
with infile = sys.stdin.readlines():
for line in infile.readlines():
columns = line.split(',')
This code is not tested as Windows Explorer just crashed on my box
(effing windows - I'm at work so no Mac. *sob*).
One thing to look out for is that 'columns' is being created each time
through the loop, which works fine. If you modified the code to append
to it instead, you would need to create it before entering the loop as
you can't append to something that doesn't exist.
More information about the Python-list