on-internet
← Community

How to not put self. when initializing every attribute in a Python class?

Stack Overflow ·

Greetings. I searched for a long time, and found many related questions with no answer for me. Despite mine seems to be a simple beginner doubt. We have a (I guess) typical class definition: class Town: def __init__(self, Name, Ruler = "Spanish Inquisition"): self.Name = Name self.Population = 0 self.LocationX = 0 self.LocationY = 0 self.Religion = "Jedi" self.Ruler = Ruler self.Products = ["Redstone", "Azaleas"] You get the idea. A lot of attributes. I need all of them. The question is: **Is there a shortcut to save all those "self."?** Am I being too lazy? I hoped for something like: with se

Comments

Sign in or sign up to comment and upvote.

No comments yet.