Ask your own question, for FREE!
Computer Science 19 Online
OpenStudy (anonymous):

python: how do i read from a file and then take the first two collumns and save them. to then compare the lines information?

OpenStudy (anonymous):

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?

OpenStudy (anonymous):

What do you mean by compare?

OpenStudy (rsmith6559):

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"

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!