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


Groups > comp.lang.python > #8899

Re: write file

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'method,': 0.07; '(there': 0.09; 'csv': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'output': 0.11; 'subject:file': 0.13; '"w")': 0.16; '(note:': 0.16; 'bieber': 0.16; 'declaimed': 0.16; 'email addr:ix.netcom.com': 0.16; 'email name:wlfraed': 0.16; 'files...': 0.16; 'fout': 0.16; 'fout.close()': 0.16; 'from:addr:ix.netcom.com': 0.16; 'from:addr:wlfraed': 0.16; 'from:name:dennis lee bieber': 0.16; 'miguel': 0.16; 'received:66.245': 0.16; 'received:dsl.mindspring.com': 0.16; 'received:mindspring.com': 0.16; 'received:wlfraed': 0.16; 'url:netcom': 0.16; 'url:wlfraed': 0.16; 'wulfraed': 0.16; 'file)': 0.19; 'input': 0.21; 'file,': 0.22; 'loop': 0.22; 'tue,': 0.23; 'url:home': 0.25; 'lee': 0.28; 'mode': 0.28; 'exit': 0.29; 'writer': 0.30; 'print': 0.32; 'list': 0.32; 'to:addr:python-list': 0.34; 'header:X-Complaints-To:1': 0.34; 'charset:us-ascii': 0.36; 'file': 0.36; 'open': 0.37; 'received:org': 0.38; 'subject:: ': 0.38; 'two': 0.38; 'header :Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'format': 0.40; 'give': 0.60; 'your': 0.60; 'phone': 0.63; 'stated': 0.65; 'here': 0.66; 'dennis': 0.77; 'not...': 0.84; 'subject:write': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: write file
Date Tue, 05 Jul 2011 22:26:14 -0700
Organization > Bestiaria Support Staff <
References <COL120-W32BE028E03A845C044AAD4DC5F0@phx.gbl>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host user-11faa32.dsl.mindspring.com
X-Newsreader Forte Agent 3.3/32.846
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.685.1309930810.1164.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1309930810 news.xs4all.nl 21855 [2001:888:2000:d::a6]:46281
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8899

Show key headers only | View raw


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


Thread

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

csiph-web