Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42560 > unrolled thread

extending class static members and inheritance

Started byFabian PyDEV <pydev@hotmail.com>
First post2013-04-02 08:27 -0500
Last post2013-04-02 08:27 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  extending class static members and inheritance Fabian PyDEV <pydev@hotmail.com> - 2013-04-02 08:27 -0500

#42560 — extending class static members and inheritance

FromFabian PyDEV <pydev@hotmail.com>
Date2013-04-02 08:27 -0500
Subjectextending class static members and inheritance
Message-ID<mailman.38.1364909383.17481.python-list@python.org>
Hi All,

I have a question.

Let says I have the following two classes:

class Base(object):
	__mylist__ = ["value1", "value2"]

	def somemethod(self):
		pass


class Derived(Base):
	__mylist__ = ["value3", "value4"]

	def anothermethod(self):
		pass
	
	


what I would like to accomplish is that the class Derived has the member __mylist__ extended or merged as ["value1", "value2", "value3", "value4"].

Is there anyway I could accomplish this?

I was thinking on accomplishing this as follows:


class Derived(Base):
	__mylist__ = Base.__mylist__ + ["value3", "value4"]

	def anothermethod(self):
		pass


Is there a better way? Perhaps a decorator?


Thanks in advance and regards,
Fabian

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web