Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38943
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'argument': 0.04; 'initialize': 0.05; 'method.': 0.05; 'class,': 0.07; 'correct.': 0.07; 'executed': 0.07; 'python': 0.09; 'created,': 0.09; 'definition,': 0.09; 'specifying': 0.09; 'worked.': 0.09; 'def': 0.10; '*a,': 0.16; '12:50': 0.16; 'notations': 0.16; 'type:': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'module': 0.19; 'equivalent': 0.20; 'parameters': 0.20; 'either.': 0.22; 'help.': 0.22; 'statement': 0.23; 'this:': 0.23; 'downloaded': 0.24; 'pass': 0.25; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; '(which': 0.26; 'errors.': 0.27; 'executing': 0.27; 'things,': 0.29; 'definition': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'error': 0.30; 'expect': 0.31; 'code': 0.31; 'getting': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'self': 0.34; 'thanks': 0.34; 'expected': 0.35; 'offered': 0.35; 'pm,': 0.35; 'something': 0.35; 'but': 0.36; 'method': 0.36; 'execute': 0.37; 'does': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'build': 0.39; 'called': 0.39; 'received:192.168': 0.40; 'think': 0.40; 'your': 0.60; 'bottom': 0.60; 'further': 0.61; "you'll": 0.62; 'thomas': 0.62; 'here': 0.65; 'received:74.208': 0.71; 'absolutely': 0.84; 'here...': 0.84; 'received:74.208.4.194': 0.84; 'analyses': 0.91; 'bob': 0.91; 'net.': 0.91; 'besides,': 0.93 |
| Date | Fri, 15 Feb 2013 13:06:14 -0500 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: inheritance and how to use it |
| References | <mailman.1819.1360947575.2939.python-list@python.org> <kflpto$suo$1@r03.glglgl.gl> <511E754A.8050506@gmail.com> |
| In-Reply-To | <511E754A.8050506@gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Provags-ID | V02:K0:sEAHmwLVdrq+A1JgiC3FPwH3j8QhqKvT3cfEeMX3YNS 1e+j8ogXwCzj8mpAZYaQKd+Cm2mYab+coyaRvRJq+grN65ATo1 DhEMYqS5uMpIyOzsGMTZpn7eWBxnMgwPuAN2PNjs3mSuNO5Y5h LDf/BhtwwRFsSH9Sr26nGbeGff1h0FCPHxVkAQAdbvR7w7GHu+ zFezjhSpzswh15o8YMdYoVFQXza2PQOAAou1QBuEbVge0HTHTL 2YJD9fpJQUVwOg5BHGJSDGKvGx/4ESKdavy2d6/yOO5dwxcCAo Z2RUamXCc6ovDp5+q+4lHFnx3sKs135beOhXji+SOLnpK0TFw= = |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1832.1360951591.2939.python-list@python.org> (permalink) |
| Lines | 67 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1360951591 news.xs4all.nl 6875 [2001:888:2000:d::a6]:45806 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:38943 |
Show key headers only | View raw
On 02/15/2013 12:50 PM, Bob Brusa wrote:
> Am 15.02.2013 18:06, schrieb Thomas Rachel:
>> 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
>
> Thomas,
> This does not work either. The error comes while python analyses the
> code - even prior to executing my program.... But what I want to achieve
> is that this clear() is executed when the class is instantiated....which
> I do with the code
>
> x = myClass("COM7")
>
> Of course, when scanning the class definition, the argument "COM7" is
> not yet known.
> Thanks for further help. Bob
>
Your error is on line 115, so what does it look like, and its context?
I expect you're never getting to the line x = myClass().
--
DaveA
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