Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38930
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.straub-nv.de!uucp.gnuu.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail |
|---|---|
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: inheritance and how to use it |
| Date | Fri, 15 Feb 2013 18:06:00 +0100 |
| Organization | A newly installed InterNetNews server |
| Message-ID | <kflpto$suo$1@r03.glglgl.gl> (permalink) |
| References | <mailman.1819.1360947575.2939.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-15; format=flowed |
| Content-Transfer-Encoding | 7bit |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130105 Thunderbird/17.0.2 |
| In-Reply-To | <mailman.1819.1360947575.2939.python-list@python.org> |
| Lines | 45 |
| NNTP-Posting-Date | 15 Feb 2013 18:10:02 CET |
| NNTP-Posting-Host | d7838b6b.newsspool1.arcor-online.net |
| X-Trace | DXC=W\a5<BQZQ3X5TOT9_N5i<Vic==]BZ:af^4Fo<]lROoRQnkgeX?EC@@PMKJo_n3DUaSK8FCa6^2FWROLF_]FfFg8_HmHg4c;jRD\ |
| X-Complaints-To | usenet-abuse@arcor.de |
| Xref | csiph.com comp.lang.python:38930 |
Show key headers only | View raw
Am 15.02.2013 17:59 schrieb Bob Brusa:
> Hi,
> I use a module downloaded from the net. Now I want to build my own
> class, based on the class SerialInstrument offered in this module - and
> in my class I would like to initialize a few things, using e. g. the
> method clear() offered by SerialInstrument. Hence I type:
>
> class myClass(SerialInstrument)
> self.clear(self)
> def f1(self, str1, str2)
> ...do something etc.
>
> I then get the message "self not know" from the statement
> self.clear(self).
Which is absolutely correct. Besides, I would have expected some syntax
errors.
You try to execute the clear() method during the definition of the
class, not during the instantiation.
Instantiation happens in the __init__() method.
You'll have to do it like this:
class myClass(SerialInstrument):
def __init__(self, *a, **k): # accept all parameters
super(myClass, self).__init__(*a, **k)
self.clear() # I don't think that self is to be given twice here...
def f1(self, str1, str2):
pass
I have tried many other notations - none worked. What
> works is however the following code - specifying myClass without the
> self.clear(self) in it:
>
> x = myClass("argument")
> x.clear()
Here the clear() is called on the object which has been created, so
after calling the __init__() above (which is, roughly, equivalent to
calling it at the bottom of __init__()).
Thomas
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
inheritance and how to use it Bob Brusa <bob.brusa@gmail.com> - 2013-02-15 17:59 +0100
Re: inheritance and how to use it Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2013-02-15 18:06 +0100
Re: inheritance and how to use it Bob Brusa <bob.brusa@gmail.com> - 2013-02-15 18:50 +0100
Re: inheritance and how to use it Dave Angel <davea@davea.name> - 2013-02-15 13:06 -0500
Re: inheritance and how to use it Bob Brusa <bob.brusa@gmail.com> - 2013-02-15 20:40 +0100
Re: inheritance and how to use it Tony the Tiger <tony@tiger.invalid> - 2013-02-19 16:04 -0600
csiph-web