KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
All classes derived from a certain base class have to define an attribute called "path". In the sense of duck typing I could rely upon definition in the subclasses: class Base: pass # no "path" variable here def Sub(Base): def __init__(self): self.path = "something/" Another possiblity would be to use the base class constructor: class Base: def __init__(self, path): self.path = path def Sub(Base): def __init__(self): super().__init__("something/") I use Python 3.1. What would you prefer and why? Is there a better way?
Tags (comma-separated)
Save Edits
Cancel