I'm newbie in Python but I want to know some tricks to make my code look cute. I know that syntax of Python allows to do this, but I don't know how. Suppose I have file with lines of format "x y z" and I want to parse it and make some objects. Now code looks like this:
class Point(object): def __init__(self, x, y, z): self.x = x; self.y = y; self.z = z; ... def load_file(file_path): points = ; with open(file_path, "r") as input_file: for line in input_file: str_point = line.split(); x = float(str_point); y = float(str_point); z = float(str_point); points.append(Point(x, y, z)); return points;
Is there any way to make this code simpler?