Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'argument': 0.04; '"""': 0.05; 'initialize': 0.05; 'method.': 0.05; 'sys': 0.05; '(self,': 0.07; 'class,': 0.07; 'correct.': 0.07; 'except:': 0.07; 'executed': 0.07; 'exit': 0.07; 'filename:fname piece:py': 0.07; 'received:192.168.178': 0.07; 'try:': 0.07; 'python': 0.09; 'cmd': 0.09; 'created,': 0.09; 'definition,': 0.09; 'res': 0.09; 'specifying': 0.09; 'worked.': 0.09; 'working:': 0.09; 'def': 0.10; '*a,': 0.16; '12:50': 0.16; 'addr):': 0.16; 'history:': 0.16; 'notations': 0.16; 'program"': 0.16; 'type:': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'module': 0.19; 'equivalent': 0.20; 'parameters': 0.20; 'skip:" 30': 0.20; 'import': 0.21; '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; 'skip:m 30': 0.26; 'errors.': 0.27; 'executing': 0.27; '>>>>': 0.29; 'things,': 0.29; 'definition': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'error': 0.30; 'expect': 0.31; 'code': 0.31; 'print': 0.32; 'getting': 0.33; 'handle': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'self': 0.34; 'thanks': 0.34; 'expected': 0.35; 'offered': 0.35; 'pm,': 0.35; 'something': 0.35; 'next': 0.35; 'but': 0.36; 'message-id:@gmail.com': 0.36; 'received:74.125': 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; 'help': 0.40; 'end': 0.40; 'think': 0.40; 'your': 0.60; 'bottom': 0.60; 'further': 0.61; 'kind': 0.61; "you'll": 0.62; 'thomas': 0.62; 'between': 0.63; 'here': 0.65; 'charset:windows-1252': 0.65; 'visa': 0.66; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:gmail.com': 0.79; 'absolutely': 0.84; 'here...': 0.84; 'right!': 0.84; 'analyses': 0.91; 'bob': 0.91; 'net.': 0.91; 'besides,': 0.93; 'instrument': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:reply-to:user-agent:mime-version:to :subject:references:in-reply-to:content-type; bh=VyBCrPwVDpoQ+T/HpIlww7iS7XOkJXI1Fr47rnP9SZY=; b=sjS0aAFC+jWQK4SOsHjSpIxp+vG7w9rdxSB++Y4ov3jKCyJ1jS0/Wo5vHpbYat9Cmq gB2Hi/mhNVOeIF/z0opgWLANnYB92owzX3uF6EWjOYvptGQPR0FinK2WTLwAV8wu6ggM 2qrdmUbvZlewvXAGJyXLWnWq0UyB6FdCelOvQuu8YZSnQRENxFq4RZebswIs/Jtzj1/s UKXIX5EMCtV+pz2lz9A7+2tC2sq5s9HzodrE1YKdu1dN1s+RXLDQFtaPPRnubCxdxea4 gpEGfXS6odIBVDWyUqZGYsxE8jfAK7T9inFvwFXQx3YRK0ZjiJEQhRNeT0RFpMi5jhwG Z4cw== X-Received: by 10.14.211.132 with SMTP id w4mr11548319eeo.36.1360957231941; Fri, 15 Feb 2013 11:40:31 -0800 (PST) Date: Fri, 15 Feb 2013 20:40:32 +0100 From: Bob Brusa User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: inheritance and how to use it References: <511E754A.8050506@gmail.com> <511E7916.60008@davea.name> In-Reply-To: <511E7916.60008@davea.name> Content-Type: multipart/mixed; boundary="------------040407080905090006030909" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: bob.brusa@gmail.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 131 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1360957233 news.xs4all.nl 6907 [2001:888:2000:d::a6]:60382 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:38953 This is a multi-part message in MIME format. --------------040407080905090006030909 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------040407080905090006030909 Content-Type: text/plain; charset=windows-1252; name="q4.py" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="q4.py" """/ edit history: 15-02-2013 Creation """ import sys import visa import time class myvisa(visa.SerialInstrument): """provide utilities to handle the instrument """ def __init__(self, addr): # accept all parameters super(myvisa, self).__init__(addr, baud_rate = 57600) self.clear() # Thomas does not think that self is to be given twice # he is right! def io (self, printstr, askstr): """combines a print and an ask-string into a single call """ res = 0 try: antw = self.ask(askstr) except: antw = "time-out" res = 1 print printstr + antw return res strich = " | "; pfeil = "->" print "start of program q4.py" iodev = "COM7" tds = myvisa(iodev) cmd = "*idn?"; tds.io(pfeil+cmd+strich,cmd) cmd = "status?"; tds.write(cmd) # exit with something in the visa-buffer and this will # lead to a de-chronization between write and reads when # executing a next program print "end of program" --------------040407080905090006030909--