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?
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.