Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #38929 > unrolled thread
| Started by | Bob Brusa <bob.brusa@gmail.com> |
|---|---|
| First post | 2013-02-15 17:59 +0100 |
| Last post | 2013-02-19 16:04 -0600 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.python
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
| From | Bob Brusa <bob.brusa@gmail.com> |
|---|---|
| Date | 2013-02-15 17:59 +0100 |
| Subject | inheritance and how to use it |
| Message-ID | <mailman.1819.1360947575.2939.python-list@python.org> |
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
</head>
<body text="#330099" bgcolor="#FFFFFF">
Hi,<br>
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:<br>
<br>
class myClass(SerialInstrument)<br>
self.clear(self)<br>
def f1(self, str1, str2)<br>
...do something etc.<br>
<br>
I then get the message "self not know" from the statement
self.clear(self). I have tried many other notations - none worked.
What works is however the following code - specifying myClass
without the self.clear(self) in it:<br>
<br>
x = myClass("argument")<br>
x.clear()<br>
<br>
How can I integrate this call into the definition of myClass? Thanks
for advice.<br>
Bob<br>
</body>
</html>
[toc] | [next] | [standalone]
| From | Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> |
|---|---|
| Date | 2013-02-15 18:06 +0100 |
| Message-ID | <kflpto$suo$1@r03.glglgl.gl> |
| In reply to | #38929 |
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
[toc] | [prev] | [next] | [standalone]
| From | Bob Brusa <bob.brusa@gmail.com> |
|---|---|
| Date | 2013-02-15 18:50 +0100 |
| Message-ID | <mailman.1826.1360950608.2939.python-list@python.org> |
| In reply to | #38930 |
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
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-02-15 13:06 -0500 |
| Message-ID | <mailman.1832.1360951591.2939.python-list@python.org> |
| In reply to | #38930 |
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
[toc] | [prev] | [next] | [standalone]
| From | Bob Brusa <bob.brusa@gmail.com> |
|---|---|
| Date | 2013-02-15 20:40 +0100 |
| Message-ID | <mailman.1840.1360957233.2939.python-list@python.org> |
| In reply to | #38930 |
[Multipart message — attachments visible in raw view] — view raw
Am 15.02.2013 19:06, schrieb Dave Angel:
> 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().
>
Hi Dave and Thomas,
yep - now its working: See also attachment q4.py
C:\Projekte\TDSsw\mypython>python q4.py
start of program q4.py
->*idn? | "SPEAG","TDS","RUID:00.00-00.00 FW:2.0000 SID:00.00-00.00
FW:01.00.00"
end of program
Thanks for your kind help - bob
[toc] | [prev] | [next] | [standalone]
| From | Tony the Tiger <tony@tiger.invalid> |
|---|---|
| Date | 2013-02-19 16:04 -0600 |
| Message-ID | <jrGdnaN_arhia77MnZ2dnUVZ8madnZ2d@giganews.com> |
| In reply to | #38929 |
On Fri, 15 Feb 2013 17:59:29 +0100, Bob Brusa wrote:
> <html>
> <head>
>
> <meta http-equiv="content-type" content="text/html;
> charset=ISO-8859-15">
> </head>
> <body text="#330099" bgcolor="#FFFFFF">
Entry > /dev/null
Sigh!
/Grrr
--
___ ___
(\_--_/) | _ ._ _|_|_ _ |o _ _ ._
( 9 9 ) |(_)| |\/ |_| |(/_ ||(_|(/_|
stripes are forever - as overripe ferrets
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web