The Dude
The Dude

Reputation: 1118

How do you search for characters in csv.reader() object?

I'm trying to look for a character/word in an csv.reader() object.

I was sure this would work:

freader = csv.reader(f)
z = freader.next()
print z

if "EE" in z:
    print "Found"
else:
    print "NOPE"

but it doesn't.. Here's the output:

['1 EE-43-JT-32439 Time;"1 EE-43-JT-32439 ValueY"']
NOPE

Anyone got any good suggestions on how I can accomplish this?

Upvotes: 0

Views: 57

Answers (1)

Rahul K P
Rahul K P

Reputation: 16081

Check inside the list.

for item in z:
   if "EE" in item:
       print "Found"
       break   # You can break the loop if the item is exits.
   else:
       print "NOPE"

You can understand the real difference here.

In [196]: 'EE' in ['1 EE-43-JT-32439 Time;"1 EE-43-JT-32439 ValueY"']
Out[196]: False
In [197]: 'EE' in ['1 EE-43-JT-32439 Time;"1 EE-43-JT-32439 ValueY"'][0]
Out[197]: True

Upvotes: 2

Related Questions