Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54524 > unrolled thread
| Started by | Peter Cacioppi <peter.cacioppi@gmail.com> |
|---|---|
| First post | 2013-09-20 17:17 -0700 |
| Last post | 2013-09-21 13:28 +1000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: mutlifile inheritance problem Peter Cacioppi <peter.cacioppi@gmail.com> - 2013-09-20 17:17 -0700
Re: mutlifile inheritance problem Chris Angelico <rosuav@gmail.com> - 2013-09-21 13:28 +1000
| From | Peter Cacioppi <peter.cacioppi@gmail.com> |
|---|---|
| Date | 2013-09-20 17:17 -0700 |
| Subject | Re: mutlifile inheritance problem |
| Message-ID | <de1efea0-3d84-49f2-832b-67bdadec57dc@googlegroups.com> |
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 Yes my post has a mistake re: polymorphism. It seems self.__class__, whether called directly or indirectly, is always going to refer to the parent of the instance class. My code works only if there are no grandparents. Bummer, but glad to learn something new. It's too bad, I really lean on reload(). It appears to be incompatible with inheritance more than one level deep.
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-09-21 13:28 +1000 |
| Message-ID | <mailman.214.1379734128.18130.python-list@python.org> |
| In reply to | #54524 |
On Sat, Sep 21, 2013 at 10:17 AM, Peter Cacioppi <peter.cacioppi@gmail.com> wrote: > It's too bad, I really lean on reload(). It appears to be incompatible with inheritance more than one level deep. Python's really not designed for reload of this nature. You can easily make a nasty mess of things. If you're working in the interactive interpreter, it's probably easier to just run a stand-alone program and restart it every time; if you're actually trying to have an application that runs long-term and can reload code on the fly, you may want to consider a language that explicitly supports that (such as Pike). ChrisA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web