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


Groups > comp.lang.python > #54407

Re: mutlifile inheritance problem

X-Received by 10.68.200.101 with SMTP id jr5mr15820894pbc.8.1379548440893; Wed, 18 Sep 2013 16:54:00 -0700 (PDT)
X-Received by 10.49.82.137 with SMTP id i9mr232822qey.16.1379548440815; Wed, 18 Sep 2013 16:54:00 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!nntp.club.cc.cmu.edu!newsfeed.news.ucla.edu!usenet.stanford.edu!y3no32427562pbx.0!news-out.google.com!z6ni59312pbu.0!nntp.google.com!z6no10236307pbz.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Wed, 18 Sep 2013 16:54:00 -0700 (PDT)
In-Reply-To <9896e047.0203211303.741f695a@posting.google.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=76.105.219.46; posting-account=WnQ31woAAAD53hPo6qPShawacgs0_foq
NNTP-Posting-Host 76.105.219.46
References <9896e047.0203211303.741f695a@posting.google.com>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <9043161b-e193-482a-a90c-42e8dfae978c@googlegroups.com> (permalink)
Subject Re: mutlifile inheritance problem
From Peter Cacioppi <peter.cacioppi@gmail.com>
Injection-Date Wed, 18 Sep 2013 23:54:00 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.lang.python:54407

Show key headers only | View raw


This is a very old topic, but here is a trick for single inheritance. (The problem you allude to isn't restricted to multiple inheritance).

Any class with a single parent simply defines this function.


    def mySuper(self) : 
        return super(self.__class__, self)
      
And then any parent function be referenced like
    self.mySuper().foo()

This includes __init__.

You can read more here.

http://atlee.ca/blog/posts/blog20081121python-reload-danger-here-be-dragons.html


On Thursday, March 21, 2002 2:03:23 PM UTC-7, Marc wrote:
> I have classes defined in different files and would like to inherit
> from a class in file A.py for a class in file B.py but am running into
> problems.  I'm using Python 1.5.2 on Windows NT
> 
> Here's a specific example:
> 
> ************************
> file cbase01.py:
> 
> class CBase:
> 
>     def __init__(self):
>         self.cclass = None
>         print "cbase"
> 
> class CImStream(CBase):
> 
>     def __init(self):
>         CBase.__init__(self)
>         print "CImStream"
> 
> *************************
> in file wrappers_A01.py: 
> 
> import cbase01
> reload(cbase01)
> 
> class ImStream_SavedBitmaps(cbase01.CImStream):
> 
>     def __init__(self):
>         cbase.CImStream.__init__(self)
>         print "SavedBitmaps"
> 
> **************************
> in file sequencer01.py
> 
> import cbase01    # the offending lines, program works 
> reload(cbase01)   # if I comment these out.
> 
> class Sequencer:
> 
>     def Append(self, item):
>         pass
> 
> *****************************
> in test02.py
> 
> import wrappers_A01
> reload(wrappers_A01)
> 
> import sequencer01
> reload(sequencer01)
> 
> x0 = wrappers_A01.ImStream_SavedBitmaps()
> ***************************************************************
> 
> If I run test02 I get the traceback
> 
> Traceback (innermost last):
>   File "<string>", line 1, in ?
>   File "D:\PythonCode\pna\eyeTracking\tests\test02.py", line 15, in ?
>     x0 = wrappers_A01.ImStream_SavedBitmaps()
>   File "D:\PythonCode\pna\eyeTracking\tests\wrappers_A01.py", line 21,
> in __init__
>     cbase.CImStream.__init__(self)
> TypeError: unbound method must be called with class instance 1st
> argument
> 
> 
> Any ideas what I am doing wrong?
> 
> Thanks,
> Marc

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: mutlifile inheritance problem Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-09-18 16:54 -0700
  Re: mutlifile inheritance problem Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-09-18 17:03 -0700
  Re: mutlifile inheritance problem Ned Batchelder <ned@nedbatchelder.com> - 2013-09-18 20:38 -0400
    Re: mutlifile inheritance problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-19 02:05 +0000

csiph-web