Question

how do i use enemurate or some other function to return these values in a txt file i input to python as a whole string

TW11 42.83 -72.94   2.1

TW22 41.727 -75.81 3.9

my work so far is

in_file =open('tow.txt','r')

for line in_infile:
    L=line.strip().split()
    Tower = L[0]
    Lat = L[1]
    Long = L[2]
    ComDis = L[3]

print (Tower,Lat,Long,ComDis)

however i can only return the first line of the input file, there are about 20 lines in the file just wanted to give a short example

Was it helpful?

Solution

In python, indentation matters. You're printing only last line. If you want to print each line, move your print inside the for look by indenting it:

in_file =open('tow.txt','r')

for line in_infile:
    L=line.strip().split()
    Tower = L[0]
    Lat = L[1]
    Long = L[2]
    ComDis = L[3]

    print (Tower,Lat,Long,ComDis)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top