Reputation: 1118
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
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