Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44242
| Date | 2013-04-23 23:18 -0400 |
|---|---|
| From | Dave Angel <davea@davea.name> |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1010.1366773516.3114.python-list@python.org> (permalink) |
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