-
Notifications
You must be signed in to change notification settings - Fork 0
/
cities.py
29 lines (25 loc) · 905 Bytes
/
cities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Cities:
file = None
# cities = []
def __init__(self, path):
# path, a pathname string with the text file containing the cities.
# the text file should contain 3 rows of data, delimited by tabs, where
# the first row is the city's number, followed by an x co-ordinate and
# a y co-ordinate.
self.file = open(path)
self.cities = []
self.parseFile()
def parseFile(self):
# convert data into list of tuples
lines = self.file.readlines()
for line in lines:
line = line.strip()
data = line.split(" ")
city = {
"number": data[0],
"x_pos": float(data[1]),
"y_pos": float(data[2])
}
self.cities.append(city)
# def pop_init():
# # generate a random initial population