Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44242
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'true,': 0.05; 'column': 0.07; 'subject:file': 0.07; '#print': 0.09; 'def': 0.12; 'columns': 0.16; 'csv': 0.16; 'main():': 0.16; 'received:74.208.4.195': 0.16; 'subject:CSV': 0.16; 'subject:Reading': 0.16; 'wrote:': 0.18; 'module': 0.19; 'code,': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'second': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'but': 0.35; 'there': 0.35; 'next': 0.36; 'starting': 0.37; 'to:addr :python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'read': 0.60; 'till': 0.61; 'first': 0.61; 'received:74.208': 0.68; 'ana': 0.84 |
| Date | Tue, 23 Apr 2013 23:18:13 -0400 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Reading a CSV file |
| References | <9d0d46e5-b579-4edc-be34-0aa8798b66f8@googlegroups.com> <mailman.1000.1366753795.3114.python-list@python.org> <665fa76f-3a19-414b-8524-c2a5bfa8b21b@googlegroups.com> <54f430e9-b0f0-42ab-86c3-37dfb3bc45bd@googlegroups.com> |
| In-Reply-To | <54f430e9-b0f0-42ab-86c3-37dfb3bc45bd@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Provags-ID | V02:K0:pUGeNE75vv09ntN7ExHBfpzmiOj/0nNny80BJnvjrDJ paAzdWhCYnVbcPZnfJEBs7uolsS3n/KckdorAtEBGYwvC8Qfx3 z38kaR8+AHc4A2nUju8TFhS7QcjipiFFYMyB9b9otBLKHUrnJD qwNcu6WUlCUymoHZrDX+t9GuGh14k6kQWabtj9J5aRYrEvT5ti HGolmJEbPmIZ+h9S/X+w3sGtHl5MFcqnPL0Jnesb07hYHHy8AR UfffusUfTZLPOwnR9rYK1amOzZOfQ8pa3RLSA+q3H29Ly4b8yb ndqFB3DPIfC2zk9jXlbyRPGNKHhuJi9DOckeOeIwmy1VvzOFQ= = |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.1010.1366773516.3114.python-list@python.org> (permalink) |
| Lines | 21 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1366773516 news.xs4all.nl 2243 [2001:888:2000:d::a6]:57501 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:44242 |
Show key headers only | View raw
On 04/23/2013 06:40 PM, Ana Dionísio wrote:
> The condition I want to meet is in the first column, so is there a way to read only the first column and if the condition is true, print the rest?
>
The CSV module will read a row at a time, but nothing gets printed till
you print it. So starting with Dan's code,
row[0] is column one of a given row, while row[1] is the next column,
and so on.
import csv
def main():
with open('test.csv', 'r') as file_:
for row in csv.reader(file_, delimiter="|"):
if row[0] == "special":
print row[1:] #print columns starting at the second
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Reading a CSV file Ana Dionísio <anadionisio257@gmail.com> - 2013-04-23 14:39 -0700
Re: Reading a CSV file Dan Stromberg <drsalists@gmail.com> - 2013-04-23 14:49 -0700
Re: Reading a CSV file Ana Dionísio <anadionisio257@gmail.com> - 2013-04-23 14:58 -0700
Re: Reading a CSV file Ana Dionísio <anadionisio257@gmail.com> - 2013-04-23 15:40 -0700
Re: Reading a CSV file Fábio Santos <fabiosantosart@gmail.com> - 2013-04-24 00:30 +0100
Re: Reading a CSV file Dave Angel <davea@davea.name> - 2013-04-23 23:18 -0400
Re: Reading a CSV file Dan Stromberg <drsalists@gmail.com> - 2013-04-23 15:34 -0700
csiph-web