def generate_random_cities(self, number_of_cities): cities = [] for i in xrange(number_of_cities): cities.append( City("City " + str(i), random.randint(0, 1000), random.randint(0, 1000))) return cities
def get_cities_from_file(self, filename): cities = [] with open(filename, "r") as input: input.readline() # skip first line for line in input: name, x, y = line.strip().split(",") cities.append(City(name, int(x), int(y))) return cities
def generate(self): cities = [] for i in xrange(self.n): cities.append(City("City " + str(i), random.randint(0, 1000), random.randint(0, 1000))) with open(self.filename, 'w') as f: f.write("City,X,Y\n") for c in cities: f.write(c.name + "," + str(c.x) + "," + str(c.y) + "\n") f.flush()