python - if x == '' wont register when reading from file -
trying program split lines 3 rows file , apply "if row1 == x:" add existing class. thats not problem, ive gotten work, except when row1 ''. tried changing input file ' ', '*', , 'k' (and on), nothing worked. thing lines in input file reads: 1234565,'streetadress1','streetadress2' lines there no streetadress1 ''. program has no problem identifying number or 'streetadress2'.
class adress(object): def __init__(self,street,ykord,xkord): self.street = street self.ykord = ykord self.xkord = xkord self.connected = [] self.anlid = [] self.distances = [] self.parent = [] self.child =[] def set_connections(self): input_file = open("kopplingar2.txt") temp = input_file.read().splitlines() l in temp: row = l.split(',') identity = row[0] streeta = row[1] streetb = row[2] if streeta == self.street: diction = {'street':streetb, 'identity':identity} self.child.append(diction) elif streeta == '': self.anlid.append(identity) print 'poop!' elif streetb == self.street , streeta != '': diction = {'street':streeta, 'identity':identity} self.parent.append(diction) print streeta
the 'print poop' see if ever occur, doesnt. should 400 lines of poop result since 75% of lines in inputfile contain ''.
i have no idea why working other rows not row1 (except '' instead of full string).
'' empty string in python. if need compare value string consisting of 2 apostrophe characters, need write streeta = "''"
.
Comments
Post a Comment