I am trying to read a text file in Python using a new Class and OOP but I can't find the right way to do it without using imperative programming like this.
def read_operators_file(file_name):
in_file=open(file_name)
for i in range(constants.HEADER_TOTAL_LINES):
in_file.readline()
operators=[]
for line in in_file:
name, nationality, domain, hours, duration = line.strip().split(', ')
duration=int(duration)
domain=tuple(domain.strip('(').strip(')').split('; '))
operators.append((name, nationality, domain, hours, duration))
in_file.close()
return operators
def read_requests_file(file_name):
in_file = open(file_name)
for i in range(constants.HEADER_TOTAL_LINES):
in_file.readline()
requests = []
for line in in_file:
name, language, domain, service, duration = line.strip().split(', ')
duration = int(duration)
requests.append((name, language, domain, service, duration))
in_file.close()
return requests
Thanks,
mikeysantana