Advertisement
Guest User

Untitled

a guest
Sep 7th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. def section_reader(file_name, n):
  2.     # Takes a file name and an integer.
  3.     # Will yield sections, each with N lines, until the file is exhausted.
  4.     with open("data.txt", encoding="utf-8") as fh:
  5.         while True:
  6.             section = [fh.readline() for _ in range(n)]
  7.             if len(section[0]):
  8.                 yield section
  9.             else:
  10.                 return
  11.  
  12. class City(object):
  13.     def __init__(self, name, time, local):
  14.         self.name  = name
  15.         self.local = local
  16.         self.time  = time
  17.  
  18.     def clean(section):
  19.         return [line.strip() for line in section[0:3]]
  20.  
  21. cities = [ City(*clean(s)) for s in section_reader('data.txt', 4) ]
  22.  
  23. for c in cities:
  24.     print [c.name, c.local, c.time]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement