Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def section_reader(file_name, n):
- # Takes a file name and an integer.
- # Will yield sections, each with N lines, until the file is exhausted.
- with open("data.txt", encoding="utf-8") as fh:
- while True:
- section = [fh.readline() for _ in range(n)]
- if len(section[0]):
- yield section
- else:
- return
- class City(object):
- def __init__(self, name, time, local):
- self.name = name
- self.local = local
- self.time = time
- def clean(section):
- return [line.strip() for line in section[0:3]]
- cities = [ City(*clean(s)) for s in section_reader('data.txt', 4) ]
- for c in cities:
- print [c.name, c.local, c.time]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement