Question: Hello again, writing a script in Python. I want to read a file by using def read_data_file, and then I want to print it in

Hello again, writing a script in Python.

I want to read a file by using def read_data_file, and then I want to print it in the screen and extract it on an output file. But after return I have a problem. I dont know how to define the variables and then print them (&extract them)

file_name="data.txt"

latitude=[]

longitude=[]

temperature=[]

def read_data_file(file_name): with open(filename) as infile: line = infile.readline() while True: line = infile.readline() if not line: break _ , lat, lon, temp, _ = line.split("|", maxsplit=5) latitude.append(lat) longitude.append(lon) temperature.append(temp) return latitude,longitude,temperature

What I though to do is (but doesn't work):

atitude,longitude,temperature = read_data_file(file_name)

Please some help with the code..

Thank you!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!