Python: appending to a base class list/tuple member -
i asked question moment ago , couldn't think of pythonic solution thought i'd throw out here improve viewpoint.
what best way extend base of operations class variable tuple/list etc in super class?
the next works...
class baseclass(object): some_class_member = (1, 2, 3, 4, 5,) class anotherclass(baseclass): some_class_member = baseclass.some_class_member + (6, 7,) = baseclass() a.some_class_member # (1, 2, 3, 4, 5) b = anotherclass() b.some_class_member # (1, 2, 3, 4, 5, 6, 7) but doesn't seem pythonic have reference baseclass name have update if name changed. there improve way go this?
baseclass in baseclass.some_class_member not mean super of anotherclass. just
baseclass.some_class_member. can access without instantiation.
>>> baseclass.some_class_member (1, 2, 3, 4, 5) if purpose access value without instantiation, simple reply no. however, access value after instantiation.
how about?
class anotherclass(baseclass): def __init__(self): self.some_class_member += (6, 7,) python
No comments:
Post a Comment