Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8899 > unrolled thread

Re: write file

Started byDennis Lee Bieber <wlfraed@ix.netcom.com>
First post2011-07-05 22:26 -0700
Last post2011-07-05 22:26 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: write file Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-07-05 22:26 -0700

#8899 — Re: write file

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2011-07-05 22:26 -0700
SubjectRe: write file
Message-ID<mailman.685.1309930810.1164.python-list@python.org>
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/

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web