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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started