Printing a list of objects of user defined class

If you just want to print the label for each object, you could use a loop or a list comprehension:

print [vertex.label for vertex in x]

But to answer your original question, you need to define the __repr__ method to get the list output right. It could be something as simple as this:

def __repr__(self):
    return str(self)

Leave a Comment