python: how do i read from a file and then take the first two collumns and save them. to then compare the lines information?
def star: f= open("star.txt") line=f.readlines() for l in lines: l.split(",")= lat , lon // the info from the first two collumns, which are separated by "," .... now : how do i compare the lat , lon of the first line and then next lines?
What do you mean by compare?
l is going to be a list of the strings between commas in the input line. This may work: def star(): prevLat = 0.0 prevLong = 0.0 lat = 0.0 long = 0.0 try: file = open( "star.txt" ) for line in file.readline(): l = line.split( ',' ) prevLat = lat prevLong = long lat = float( l[ 0 ] ) long = float( l[ 1 ] ) if( lat > prevLat ): print "north" elif( lat < prevLat ): print "south" elif( long > prevLong ): print "east" else: print "west" file.close() else: print "the program made a boo boo"
Join our real-time social learning platform and learn together with your friends!