Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8899
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: write file |
| Date | 2011-07-05 22:26 -0700 |
| Organization | > Bestiaria Support Staff < |
| References | <COL120-W32BE028E03A845C044AAD4DC5F0@phx.gbl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.685.1309930810.1164.python-list@python.org> (permalink) |
On Tue, 5 Jul 2011 14:25:22 -0700, miguel olivares varela
<klica_sk8@hotmail.com> declaimed the following in
gmane.comp.python.general:
> fout = open("out.csv", "w")
Here you open -- in WRITE mode (create a NEW file) your output file
> print >>fout, lastname, firstname, timestamp, phone
> fout.close()
> sys.exit()
And these two CLOSE said file, and EXIT the program.
You've already stated these are CSV format files... So why not...
open output file
give output file to CSV writer
loop over input files (note: need to make sure output is not in the list
of input files!)
open input file
give file to CSV reader
loop read line from csv.reader
do any modifications needed
write line via csv.writer
del csv.reader (there is no csv close method, this step is paranoia)
close input file
del csv.writer
close output file
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: write file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-07-05 22:26 -0700
csiph-web