Python Array Parsing -
i super new python , running stupid problem, first python code too...
i splitting string array , want compare various elements. printing array beforehand list of elements, sure count right. code below:
to print array
def printarray(a): in range (0,len(a)): print( "%s - %s " % (i, a[i]) ) print("\n\n\n--------\n\n\n") output: 0 - 2014-04-08 1 - 19:00:02,336 2 - info 3 - core.solrcore ..... i trying parse now:
if temp[2] "info": print (temp[2]) i can't figure out why not evaluating true. can't work. i've tried comparing is, double, single quotes, nothing working. i've tried sample code, assign value array , run comparison way , works exact same code.
d = ['info'] if d[0] 'info': print("works") this making me appreciate perl more , more...
you need test string equality == not is. is tests it's same object in memory. not guaranteed strings, though is, python tries avoid creating same string on , on in memory.
typically use is singletons none.
if doesn't work, recommend investigate checking type, length , representation of string.
do this:
word = temp[2] type(word) # expect str len(word) # expect 4 print repr(word) # expect 'info'
Comments
Post a Comment