Re: INHERITANCE in python3

2019-12-19 Thread Ethan Furman
On 12/19/2019 06:22 AM, Pieter van Oostrum wrote: Random832 writes: On Wed, Dec 18, 2019, at 23:10, wrote: [vahid asadi] my problem here is why this attribute is not recognize by python and it raise an traceback error that said 'there is no such p.family attribute'. although i use multiple

Re: INHERITANCE in python3

2019-12-19 Thread Pieter van Oostrum
Random832 writes: > On Wed, Dec 18, 2019, at 23:10, vahid asadi via Python-list wrote: >> HI guys this is my first post on python mailing lists ever and i glad >> to do this. >> my problem here is why this attribute is not recognize by python and it >> raise an traceback error that said 'there

Re: INHERITANCE in python3

2019-12-18 Thread Random832
On Wed, Dec 18, 2019, at 23:10, vahid asadi via Python-list wrote: > HI guys this is my first post on python mailing lists ever and i glad > to do this. > my problem here is why this attribute is not recognize by python and it > raise an traceback error that said 'there is no such p.family > att

Re: Inheritance in Python

2017-04-24 Thread Steve D'Aprano
On Mon, 24 Apr 2017 10:10 pm, id23...@gmail.com wrote: > I do not quite understand how inheritance works in Python. [...] > class mainCL(): > def __init__(self): > self.path1 = "/a" > self.path2 = "/b" > > class secondCL(mainCL): > def __init__(newID): > self

Re: inheritance and how to use it

2013-02-15 Thread Bob Brusa
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

Re: inheritance and how to use it

2013-02-15 Thread Dave Angel
On 02/15/2013 01:28 PM, Bob Brusa wrote: to make it more clear, I attach a cut-down version of my program. It includes comments to explain in more detail what my problem is. Bob Good job cutting down the sample. Naturally, it'd have been smart to tell us you don't get the same trace

Re: inheritance and how to use it

2013-02-15 Thread Bob Brusa
Am 15.02.2013 19:03, schrieb Dave Angel: On 02/15/2013 12:23 PM, Bob Brusa wrote: Am 15.02.2013 18:11, schrieb Dave Angel: On 02/15/2013 11:59 AM, Bob Brusa wrote: 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

Re: inheritance and how to use it

2013-02-15 Thread 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

Re: inheritance and how to use it

2013-02-15 Thread Dave Angel
On 02/15/2013 12:23 PM, Bob Brusa wrote: Am 15.02.2013 18:11, schrieb Dave Angel: On 02/15/2013 11:59 AM, Bob Brusa wrote: 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 i

Re: inheritance and how to use it

2013-02-15 Thread Bob Brusa
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 m

Re: inheritance and how to use it

2013-02-15 Thread Bob Brusa
Am 15.02.2013 18:11, schrieb Dave Angel: On 02/15/2013 11:59 AM, Bob Brusa wrote: 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 me

Re: inheritance and how to use it

2013-02-15 Thread 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. He

Re: inheritance and how to use it

2013-02-15 Thread Dave Angel
On 02/15/2013 11:59 AM, Bob Brusa wrote: 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.

Re: Inheritance Question

2012-10-18 Thread Jeff Jeffries
On Thu, Oct 18, 2012 at 10:51 AM, Dave Angel wrote: > On 10/18/2012 10:10 AM, Jeff Jeffries wrote: > > Hello everybody > > > > When I set "AttributeChanges" in my example, it sets the same value for > all > > other subclasses. Can someone help me with what the name of this behavior > > is (mutabl

Re: Inheritance Question

2012-10-18 Thread Dave Angel
On 10/18/2012 10:10 AM, Jeff Jeffries wrote: > Hello everybody > > When I set "AttributeChanges" in my example, it sets the same value for all > other subclasses. Can someone help me with what the name of this behavior > is (mutable class global?) ? I don't know any keywords... having > troubl

Re: Inheritance Question

2012-10-18 Thread Oscar Benjamin
On 18 October 2012 15:10, Jeff Jeffries wrote: > Hello everybody > > When I set "AttributeChanges" in my example, it sets the same value for all > other subclasses. Can someone help me with what the name of this behavior is > (mutable class global?) ? I don't know any keywords... having troub

Re: inheritance

2012-04-05 Thread Ian Kelly
On Thu, Apr 5, 2012 at 11:50 AM, Yagnesh Raghava Yakkala wrote: >>>you will have >>> to pass the instance in explicitly as the self argument.  For example: >> >>> B.foo(x)  # calls B.foo directly with instance x > > After follow up, I see one problem(can i say that?) with this. With python > overw

[solved] Re: inheritance

2012-04-05 Thread Yagnesh Raghava Yakkala
Hello, With Chris and Ian help (Thank you both) I end up writing the example script like this,(just for the record) - #! /usr/bin/env python3 # -*- coding: utf-8 -*- class A(object): def __init__(self, a): print('a = ', a) self.a = a

Re: inheritance

2012-04-05 Thread Chris Angelico
On Fri, Apr 6, 2012 at 4:09 AM, Yagnesh Raghava Yakkala wrote: > Thanks for explaining. It makes sense. I see that python interpreter can > instantly tell the list of defined methods in the super class(es). So "keeping > track" thing is not at all a problem. > > Thanks a lot again. Most welcome!

Re: inheritance

2012-04-05 Thread Yagnesh Raghava Yakkala
Hello Chris, Chris Angelico writes: > > If you're subclassing something, you should generally work with the > intention that an instance of your class will function viably in any > situation in which an instance of the parent is wanted. So if you're > writing a method of the same name as one in

Re: inheritance

2012-04-05 Thread Chris Angelico
On Fri, Apr 6, 2012 at 3:50 AM, Yagnesh Raghava Yakkala wrote: > After follow up, I see one problem(can i say that?) with this. With python > overwriting methods of super class(es), one need to keep track of all the > methods ever defined in the super class(es). do everybody do a check before > wr

Re: inheritance

2012-04-05 Thread Yagnesh Raghava Yakkala
Hello Ian, Yagnesh Raghava Yakkala writes: > Hello Ian, > > Ian Kelly writes: [snipped 21 lines] > >>you will have >> to pass the instance in explicitly as the self argument. For example: > >> B.foo(x) # calls B.foo directly with instance x After follow up, I see one problem(can i say tha

Re: inheritance

2012-04-05 Thread Yagnesh Raghava Yakkala
Hello Ian, Ian Kelly writes: > On Thu, Apr 5, 2012 at 10:50 AM, yag wrote: >> three classes A,B,C and instance x. >> >> now how can I call methods foo in class A and B using 'x' instance. (I hope I >> could pronounce the terminology correct) > > Do you mean that you want C.foo to call B.foo, a

Re: inheritance

2012-04-05 Thread yagnesh
Chris Angelico writes: > On Fri, Apr 6, 2012 at 2:50 AM, yag wrote: >> [snipped 19 lines] > In each case, you are overriding the foo() method, so your instance > will only execute the last one. If you want to chain to the others, > you need to write your methods to do so - which is what you've

Re: inheritance

2012-04-05 Thread Ian Kelly
On Thu, Apr 5, 2012 at 10:50 AM, yag wrote: > three classes A,B,C and instance x. > > now how can I call methods foo in class A and B using 'x' instance. (I hope I > could pronounce the terminology correct) Do you mean that you want C.foo to call B.foo, and B.foo to call A.foo? If that is the ca

Re: inheritance

2012-04-05 Thread Chris Angelico
On Fri, Apr 6, 2012 at 2:50 AM, yag wrote: > > Hello, > > I am new to python (or to any programming language). My first post on this > list, > so please go easy. Apologies if its a FAQ. Welcome! > class A(object): >    def foo(self): >        print('printing from foo in A = ',self.a) > > class

Re: inheritance, multiple inheritance and the weaklist and instance dictionaries

2011-02-09 Thread Rouslan Korneychuk
On 02/09/2011 08:40 PM, Carl Banks wrote: I explained why in my last post; there's a bunch of reasons. Generally you can't assume someone's going to go through the type structure to find the object's dict, nor can you expect inherited methods to always use the derived class's type structure (some

Re: inheritance, multiple inheritance and the weaklist and instance dictionaries

2011-02-09 Thread Carl Banks
On Feb 9, 3:11 pm, Rouslan Korneychuk wrote: > On 02/09/2011 04:58 PM, Carl Banks wrote: > > On Feb 9, 1:14 pm, Rouslan Korneychuk  wrote: > >> On 02/09/2011 02:42 PM, Carl Banks wrote: > >>> This is the only case I can think of where the > >>> layout conflict would be caused by a type setting tp_

Re: inheritance, multiple inheritance and the weaklist and instance dictionaries

2011-02-09 Thread Rouslan Korneychuk
On 02/09/2011 05:02 PM, Carl Banks wrote: On Feb 9, 1:14 pm, Rouslan Korneychuk wrote: Each Python class is a wrapper for a C++ class. Also, if you want my opinion (you probably don't after you've already gone to so much trouble, but here it is anyway): No, your opinion is quite welcome.

Re: inheritance, multiple inheritance and the weaklist and instance dictionaries

2011-02-09 Thread Rouslan Korneychuk
On 02/09/2011 04:58 PM, Carl Banks wrote: On Feb 9, 1:14 pm, Rouslan Korneychuk wrote: On 02/09/2011 02:42 PM, Carl Banks wrote: This is the only case I can think of where the layout conflict would be caused by a type setting tp_dictoffset. No, actually I have code that is roughly equivalent

Re: inheritance, multiple inheritance and the weaklist and instance dictionaries

2011-02-09 Thread Carl Banks
On Feb 9, 1:14 pm, Rouslan Korneychuk wrote: > Each Python class is a wrapper for a C++ class. Also, if you want my opinion (you probably don't after you've already gone to so much trouble, but here it is anyway): It's not worth it to mimic the C++ type hierarchy in Python. Just wrap each C++ c

Re: inheritance, multiple inheritance and the weaklist and instance dictionaries

2011-02-09 Thread Carl Banks
On Feb 9, 1:14 pm, Rouslan Korneychuk wrote: > On 02/09/2011 02:42 PM, Carl Banks wrote: > > This is the only case I can think of where the > > layout conflict would be caused by a type setting tp_dictoffset. > > No, actually I have code that is roughly equivalent to the following > pseudocode: >

Re: inheritance, multiple inheritance and the weaklist and instance dictionaries

2011-02-09 Thread Rouslan Korneychuk
On 02/09/2011 02:42 PM, Carl Banks wrote: On Feb 9, 10:54 am, Rouslan Korneychuk wrote: I'm working on a program that automatically generates C++ code for a Python extension and I noticed a few limitations when using the weaklist and instance dictionaries (tp_weaklistoffset and tp_dictoffset).

Re: inheritance, multiple inheritance and the weaklist and instance dictionaries

2011-02-09 Thread Carl Banks
On Feb 9, 10:54 am, Rouslan Korneychuk wrote: > I'm working on a program that automatically generates C++ code for a > Python extension and I noticed a few limitations when using the weaklist > and instance dictionaries (tp_weaklistoffset and tp_dictoffset). This is > pertaining to the C API. > >

Re: Inheritance and name clashes

2010-10-04 Thread Steven D'Aprano
On Mon, 04 Oct 2010 09:51:18 -0700, Dennis Lee Bieber wrote: > On 04 Oct 2010 05:08:20 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general: > > >> from luncheon_meats import Ham >> >> class Spam(Ham): >> def __init__(self): >> self.__x = "yummy" >> >> >>

Re: Inheritance and name clashes

2010-10-04 Thread Steven D'Aprano
On Sun, 03 Oct 2010 21:32:25 -0700, Dennis Lee Bieber wrote: > Well... then use the double __ prefix so your instance variables > have a class specific name... That IS what the __ are designed to do -- > ensure that the name, as used /in/ that class itself is unique, and not > referencing so

Re: Inheritance and name clashes

2010-10-03 Thread Chris Torek
In article <14cf8b45-a3c0-489f-8aa9-a75f0f326...@n3g2000yqb.googlegroups.com> Rock wrote: >I've really been wondering about the following lately. The question is >this: if there are no (real) private or protected members in Python, >how can you be sure, when inheriting from another class, that yo

Re: Inheritance and name clashes

2010-10-03 Thread Steven D'Aprano
On Mon, 04 Oct 2010 11:57:18 +1300, Gregory Ewing wrote: > Rock wrote: >> What if the >> library I'm using doesn't realase the source, or what if I just can't >> get my hands on it for some reason or another? > > You can always use dir() on an instance of the class to find out what > names it's u

Re: Inheritance and name clashes

2010-10-03 Thread Steven D'Aprano
On Sun, 03 Oct 2010 15:04:17 -0700, Rock wrote: > Thanks for the reply. No, I was just working with a normal library class > which was supposed to be derived. So that's what I did, but in the > process I found myself needing to create an instance variable and it > dawned on me: "how do I know I'm

Re: Inheritance and name clashes

2010-10-03 Thread Steve Howell
On Oct 3, 5:17 pm, MRAB wrote: > On 04/10/2010 00:06, Steve Howell wrote:> On Oct 3, 3:57 pm, Gregory > Ewing  wrote: > >> Rock wrote: > >>> What if the > >>> library I'm using doesn't realase the source, or what if I just can't > >>> get my hands on it for some reason or another? > > >> You can

Re: Inheritance and name clashes

2010-10-03 Thread Steve Howell
On Oct 3, 5:13 pm, Carl Banks wrote: > On Oct 3, 3:04 pm, Rock wrote: > > > No, I was just working with a normal library > > class which was supposed to be derived. So that's what I did, but in > > the process I found myself needing to create an instance variable and > > it dawned on me: "how do

Re: Inheritance and name clashes

2010-10-03 Thread MRAB
On 04/10/2010 00:06, Steve Howell wrote: On Oct 3, 3:57 pm, Gregory Ewing wrote: Rock wrote: What if the library I'm using doesn't realase the source, or what if I just can't get my hands on it for some reason or another? You can always use dir() on an instance of the class to find out what

Re: Inheritance and name clashes

2010-10-03 Thread Carl Banks
On Oct 3, 3:04 pm, Rock wrote: > No, I was just working with a normal library > class which was supposed to be derived. So that's what I did, but in > the process I found myself needing to create an instance variable and > it dawned on me: "how do I know I'm not clobbering something > here???" ...

Re: Inheritance and name clashes

2010-10-03 Thread Paul Rubin
Arnaud Delobelle writes: > I've been reading c.l.python for years (on and off) and I can't recall > anybody saying this has been a problem in practise. It has been a problem for me at least once. I blew a good chunk of a day debugging a problem that turned out due to my clobbering something in

Re: Inheritance and name clashes

2010-10-03 Thread Steve Howell
On Oct 3, 3:57 pm, Gregory Ewing wrote: > Rock wrote: > > What if the > > library I'm using doesn't realase the source, or what if I just can't > > get my hands on it for some reason or another? > > You can always use dir() on an instance of the class to > find out what names it's using. > Indeed

Re: Inheritance and name clashes

2010-10-03 Thread Gregory Ewing
Rock wrote: What if the library I'm using doesn't realase the source, or what if I just can't get my hands on it for some reason or another? You can always use dir() on an instance of the class to find out what names it's using. -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheritance and name clashes

2010-10-03 Thread Steve Howell
On Oct 3, 3:04 pm, Rock wrote: > > Object-oriented designs are difficult to design in any programming > > language, and it helps to have some sort of concrete problem to drive > > the discussion.  Are you working on a particular design where you > > think Python's philosophy will inhibit good desi

Re: Inheritance and name clashes

2010-10-03 Thread Arnaud Delobelle
Arnaud Delobelle writes: > I've been reading c.l.python for years (on and off) and I can't recall > anybody saying this has been a problem in practise. Arghh! Practice, I meant practice! -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheritance and name clashes

2010-10-03 Thread Arnaud Delobelle
Rock writes: >> Object-oriented designs are difficult to design in any programming >> language, and it helps to have some sort of concrete problem to drive >> the discussion.  Are you working on a particular design where you >> think Python's philosophy will inhibit good design?  My take on Pytho

Re: Inheritance and name clashes

2010-10-03 Thread Rock
> Object-oriented designs are difficult to design in any programming > language, and it helps to have some sort of concrete problem to drive > the discussion.  Are you working on a particular design where you > think Python's philosophy will inhibit good design?  My take on Python > is that it focu

Re: Inheritance and name clashes

2010-10-03 Thread Steve Howell
On Oct 3, 1:07 pm, Rock wrote: > Hi all :) > > I've really been wondering about the following lately. The question is > this: if there are no (real) private or protected members in Python, > how can you be sure, when inheriting from another class, that you > won't wind up overriding, and possibly

Re: Inheritance and name clashes

2010-10-03 Thread Gary Herron
On 10/03/2010 01:07 PM, Rock wrote: Hi all :) I've really been wondering about the following lately. The question is this: if there are no (real) private or protected members in Python, how can you be sure, when inheriting from another class, that you won't wind up overriding, and possibly clobb

Re: Inheritance and forward references (prototypes)

2009-06-22 Thread Lorenzo Di Gregorio
On 21 Jun., 22:51, Scott David Daniels wrote: > LorenzoDiGregoriowrote: > > On 21 Jun., 01:54, Dave Angel wrote: > >> ... > >> class B(object): > >>     def __init__(self,test=None): > >>         if test==None: > >>             test = A() > >>         self.obj =() > >>         return > > ... > >

Re: Inheritance and forward references (prototypes)

2009-06-22 Thread Bruno Desthuilliers
Dave Angel a écrit : (snip Default arguments of class methods are evaluated during the definition of the class Default arguments of functions are eval'd during the execution of the def statement. The fact that you use a def statement within a class statement's body is totally orthogonal -

Re: Inheritance and forward references (prototypes)

2009-06-22 Thread Bruno Desthuilliers
Piet van Oostrum a écrit : Steven D'Aprano (SD) wrote: (snip) SD> # A.__base__ = DebugA ## Uncomment this line for debugging. A.__base__ = DebugA TypeError: readonly attribute Make that: A.__bases__ = DebugA, or even better (readability-wise): A.__bases__ = (DebugA,) Just the sam

Re: Inheritance and forward references (prototypes)

2009-06-21 Thread Scott David Daniels
Lorenzo Di Gregorio wrote: On 21 Jun., 01:54, Dave Angel wrote: ... class B(object): def __init__(self,test=None): if test==None: test = A() self.obj =() return ... I had also thought of using "None" (or whatever else) as a marker but I was curious to fi

Re: Inheritance and forward references (prototypes)

2009-06-21 Thread Lie Ryan
Lorenzo Di Gregorio wrote: > I had also thought of using "None" (or whatever else) as a marker but > I was curious to find out whether there are better ways to supply an > object with standard values as a default argument. > In this sense, I was looking for problems ;-) > > Of course the observati

Re: Inheritance and forward references (prototypes)

2009-06-21 Thread Lorenzo Di Gregorio
On 21 Jun., 01:54, Dave Angel wrote: > LorenzoDiGregoriowrote: > > On Jun 20, 8:43 pm, Dave Angel wrote: > > >>LorenzoDiGregoriowrote: > > >>> Hi, > > >>> I'm wondering what would be the preferred way to solve the following > >>> forward reference problem: > > >>>

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Dave Angel
Lorenzo Di Gregorio wrote: On Jun 20, 8:43 pm, Dave Angel wrote: Lorenzo Di Gregorio wrote: Hi, I'm wondering what would be the preferred way to solve the following forward reference problem: --- class BaseA(object): def __init__(

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Rhodri James
On Sat, 20 Jun 2009 21:26:56 +0100, Lorenzo Di Gregorio wrote: Thank you for your help: I'm working on a rather large source, but I think I have isolated the problem now. This listing generates an error: --- class BaseA(object): def __init__(se

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Lorenzo Di Gregorio
On Jun 20, 8:43 pm, Dave Angel wrote: > Lorenzo Di Gregorio wrote: > > Hi, > > > I'm wondering what would be the preferred way to solve the following > > forward reference problem: > > > --- > > class BaseA(object): > >     def __init__(self): > >         return

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Piet van Oostrum
> Steven D'Aprano (SD) wrote: >SD> Lorenzo Di Gregorio wrote: >>> Hi, >>> >>> I'm wondering what would be the preferred way to solve the following >>> forward reference problem: >SD> You don't actually explain what is the problem. Fortunately, I'm good at >SD> guessing, and I think I can gu

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Dave Angel
Lorenzo Di Gregorio wrote: Hi, I'm wondering what would be the preferred way to solve the following forward reference problem: --- class BaseA(object): def __init__(self): return class DebugA(BaseA): def __init__(self): return # here

Re: Inheritance and forward references (prototypes)

2009-06-20 Thread Steven D'Aprano
Lorenzo Di Gregorio wrote: > Hi, > > I'm wondering what would be the preferred way to solve the following > forward reference problem: You don't actually explain what is the problem. Fortunately, I'm good at guessing, and I think I can guess what your problem is (see below): >

Re: Inheritance and Design Question

2009-05-28 Thread Steven D'Aprano
On Wed, 27 May 2009 17:21:23 -0400, Terry Reedy wrote: > super() was designed for multiple inheritance. Surely you mean that super() was designed for *inheritance*, multiple or singular? Working with single inheritance is part of the design, not an accident of implementation. > The only reaso

Re: Inheritance and Design Question

2009-05-28 Thread Jean-Michel Pichavant
imageguy wrote: I have an object the I would like to use as a base class. Some of the methods I would like to override completely, but others I would simply like to call the base class method and use the return value in the child method. The purpose here is to eliminate the duplication of valua

Re: Inheritance and Design Question

2009-05-27 Thread Carl Banks
On May 27, 12:58 pm, imageguy wrote: > I have an object the I would like to use as a base class.  Some of the > methods I would like to override completely, but others I would simply > like to call the base class method and use the return value in the > child method.  The purpose here is to elimin

Re: Inheritance and Design Question

2009-05-27 Thread Andre Engels
On Wed, May 27, 2009 at 9:58 PM, imageguy wrote: > I have an object the I would like to use as a base class.  Some of the > methods I would like to override completely, but others I would simply > like to call the base class method and use the return value in the > child method.  The purpose here

Re: Inheritance and Design Question

2009-05-27 Thread Terry Reedy
imageguy wrote: I have an object the I would like to use as a base class. Some of the methods I would like to override completely, but others I would simply like to call the base class method and use the return value in the child method. The purpose here is to eliminate the duplication of valua

Re: Inheritance and Design Question

2009-05-27 Thread Matimus
On May 27, 12:58 pm, imageguy wrote: > I have an object the I would like to use as a base class.  Some of the > methods I would like to override completely, but others I would simply > like to call the base class method and use the return value in the > child method.  The purpose here is to elimin

Re: Inheritance and Design Question

2009-05-27 Thread Scott David Daniels
imageguy wrote: I have an object the I would like to use as a base class. Some of the methods I would like to override completely, but others I would simply like to call the base class method and use the return value in the child method. The purpose here is to eliminate the duplication of valua

Re: Inheritance problem

2008-11-05 Thread Mr . SpOOn
On Wed, Nov 5, 2008 at 6:59 PM, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > You need to call the __init__ of NoteSet inside Scale, as otherwise the > instance isn't properly initialized. Thanks, solved. -- http://mail.python.org/mailman/listinfo/python-list

Re: Inheritance problem

2008-11-05 Thread Diez B. Roggisch
Mr.SpOOn wrote: > Hi, > I have a problem with this piece of code: > > > class NoteSet(OrderedSet): > def has_pitch(self): > pass > def has_note(self): > pass > > class Scale(NoteSet): > def __init__(self, root, type): > self.append(root) > self.type =

Re: Inheritance but only partly?

2008-10-05 Thread George Sakkis
On Oct 3, 11:56 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 03 Oct 2008 03:32:52 -0700, Michele Simionato wrote: > > IMO, if you have methods that you want to use in different classes, this > > is hint that > > you are in need of generic functions. See this blog post

Re: Inheritance but only partly?

2008-10-03 Thread Steven D'Aprano
On Fri, 03 Oct 2008 03:32:52 -0700, Michele Simionato wrote: > IMO, if you have methods that you want to use in different classes, this > is hint that > you are in need of generic functions. See this blog post for an example: > > http://www.artima.com/weblogs/viewpost.jsp?thread=237764 That's a

Re: Inheritance but only partly?

2008-10-03 Thread Simon Brunning
2008/10/3 Tim Rowe <[EMAIL PROTECTED]>: > As others have said, no. What nobody seems to have said yet is why. If > Y descends from X, you are saying that Y is an X; that a Y can be used > anywhere an X can. If Y doesn't support some methods of X then it is > *not* an X, and *can't* be used anywher

Re: Inheritance but only partly?

2008-10-03 Thread Tim Rowe
2008/10/2 process <[EMAIL PROTECTED]>: > Let's say I have a class X which has 10 methods. > > I want class Y to inherit 5 of them. > > Can I do that? As others have said, no. What nobody seems to have said yet is why. If Y descends from X, you are saying that Y is an X; that a Y can be used anywhe

Re: Inheritance but only partly?

2008-10-03 Thread Michele Simionato
On Oct 2, 10:16 pm, process <[EMAIL PROTECTED]> wrote: > Let's say I have a class X which has 10 methods. > > I want class Y to inherit 5 of them. > > Can I do that? Can I do something along the lines of super(Y, exclude > method 3 4 7 9 10) ? Don't use inheritance, use delegation or just copy the

Re: Inheritance but only partly?

2008-10-03 Thread Peter Otten
greg wrote: >> class Mask(object): >> def m3(self): raise NotImplementedError >> def m4(self): raise NotImplementedError > >> What's the name of this python design pattern? :-) > > Don't know. Perhaps we could call it the FigLeaf pattern > (covering up what you don't want seen)? Braghettone ;)

Re: Inheritance but only partly?

2008-10-03 Thread greg
[EMAIL PROTECTED] wrote: class Mask(object): def m3(self): raise NotImplementedError def m4(self): raise NotImplementedError What's the name of this python design pattern? :-) Don't know. Perhaps we could call it the FigLeaf pattern (covering up what you don't want seen)? There's a

Re: Inheritance but only partly?

2008-10-02 Thread bearophileHUGS
Gary Herron: > You can also redefine the ones you don't want inherited: > class A: > def DontInheritMe(self, ...): >... > Class B(A): > def DontInheritMe(self, ...): >raise NotImplementedError // Or some such I have never used something like this, but the OP may use a maski

Re: Inheritance but only partly?

2008-10-02 Thread Aaron "Castironpi" Brady
On Oct 2, 3:16 pm, process <[EMAIL PROTECTED]> wrote: > Let's say I have a class X which has 10 methods. > > I want class Y to inherit 5 of them. > > Can I do that? Can I do something along the lines of super(Y, exclude > method 3 4 7 9 10) ? That implies that the 5 you do include don't rely on or

Re: Inheritance but only partly?

2008-10-02 Thread Gary Herron
Gary Herron wrote: > process wrote: > >> Let's say I have a class X which has 10 methods. >> >> I want class Y to inherit 5 of them. >> >> Can I do that? Can I do something along the lines of super(Y, exclude >> method 3 4 7 9 10) ? >> >> -- >> http://mail.python.org/mailman/listinfo/python-list

Re: Inheritance but only partly?

2008-10-02 Thread Matimus
On Oct 2, 1:16 pm, process <[EMAIL PROTECTED]> wrote: > Let's say I have a class X which has 10 methods. > > I want class Y to inherit 5 of them. > > Can I do that? Can I do something along the lines of super(Y, exclude > method 3 4 7 9 10) ? I think the noral way of doing that is to split the ori

Re: Inheritance but only partly?

2008-10-02 Thread Gary Herron
process wrote: > Let's say I have a class X which has 10 methods. > > I want class Y to inherit 5 of them. > > Can I do that? Can I do something along the lines of super(Y, exclude > method 3 4 7 9 10) ? > > -- > http://mail.python.org/mailman/listinfo/python-list > No. But why do yo care? Yo

Re: Inheritance crossover packages

2008-08-11 Thread Carl Banks
On Aug 11, 2:41 pm, Johannes Bauer <[EMAIL PROTECTED]> wrote: > Hello group, > > I'm having a seemingly simple problem. I want to generate a hierarchy of > modules, like this one: > > GenerationScripts/ > GenerationScripts/dhcp > GenerationScripts/bind9 > > And the files: > > GenerationScripts/dhcp

Re: Inheritance crossover packages

2008-08-11 Thread Bruno Desthuilliers
Johannes Bauer a écrit : Hello group, I'm having a seemingly simple problem. I want to generate a hierarchy of modules, like this one: GenerationScripts/ GenerationScripts/dhcp GenerationScripts/bind9 And the files: GenerationScripts/dhcp/__init__.py GenerationScripts/bind9/generator.py Gen

Re: inheritance question...

2008-06-23 Thread Eric Brunel
Preamble: when posting a brand new question, you'd better not replying to an existing completely unrelated message. In most viewers, this will cause your message to appear in the thread for the original question and far less people will see it. So better create a brand new thread. On Fri, 2

Re: inheritance question...

2008-06-20 Thread Guilherme Polo
On Fri, Jun 20, 2008 at 6:19 PM, Hamish McKenzie <[EMAIL PROTECTED]> wrote: > > I have this class: > > class Vector(object): > TOL = 1e-5 > def __eq__( self, other, tolerance=TOL ): > print tolerance > > > shortened for clarity obviously. so I want to subclass this class like > s

Re: Inheritance confusion

2008-04-19 Thread Hook
Thanks to everyone who replied. Kay and Mark put me on the right track immediately. Ben is quite right - the fragment that I posted couldn't have given that error, but I didn't want to post the whole thing - perhaps wrongly, I thought it wouldn't help clarify what I thought the problem was. And

Re: Inheritance confusion

2008-04-19 Thread Ben Finney
Hook <[EMAIL PROTECTED]> writes: > I'm having a problem with multiple inheritance You aren't alone. Multiple inheritance (MI) is difficult to implement, and once implemented, usually difficult to understand and sometimes counterintuitive. I recommend you read and absorb the article "The Truth ab

Re: Inheritance confusion

2008-04-19 Thread Mark Shroyer
In article <[EMAIL PROTECTED]>, Hook <[EMAIL PROTECTED]> wrote: > Hi, > > I'm having a problem with multiple inheritance - it's clearly something > I've missed, but the web pages and books that I've consulted aren't > helping, so I'll throw myself on the mercy and collective wisdom of > Usene

Re: Inheritance confusion

2008-04-19 Thread 7stud
On Apr 19, 12:37 am, Hook <[EMAIL PROTECTED]> wrote: > Hi, > > I'm having a problem with multiple inheritance - it's clearly something > I've missed, but the web pages and books that I've consulted aren't > helping, so I'll throw myself on the mercy and collective wisdom of > Usenet! > > I've got 4

Re: Inheritance confusion

2008-04-19 Thread Peter Otten
Hook wrote: > When I run the script I get this: > > Traceback (most recent call last): > File "./3.py", line 20, in > Obj.Connect ('Database') > File "/mnt/isis/Projects/Python/Learning/DB_m.py", line 102, in Connect > self.TRACE ("DB::Connect (" + database + "," + mode) > File "/m

Re: Inheritance confusion

2008-04-19 Thread Kay Schluehr
On 19 Apr., 08:37, Hook <[EMAIL PROTECTED]> wrote: > Traceback (most recent call last): > File "./3.py", line 20, in > Obj.Connect ('Database') > File "/mnt/isis/Projects/Python/Learning/DB_m.py", line 102, in Connect > self.TRACE ("DB::Connect (" + database + "," + mode) > File "/m

Re: Inheritance question

2008-03-25 Thread Tzury Bar Yochay
Hi all, I would like to thank you all for all the suggestions. what I did was simply extending the super class data with data from its child using the id example, Foo.id = 1 is now = [1] and the FooSon does self.id.append(2) the system designer wanted inheritance+java and I wanted Python +Functi

Re: Inheritance question

2008-03-25 Thread castironpi
On Mar 25, 12:01 pm, Robert Bossy <[EMAIL PROTECTED]> wrote: > Hi, > > I'm not sure what you're trying to actually achieve, but it seems that > you want an identificator for classes, not for instances. In this case, > setting the id should be kept out of __init__ since it is an instance > initializ

Re: Inheritance question

2008-03-25 Thread Robert Bossy
Hi, I'm not sure what you're trying to actually achieve, but it seems that you want an identificator for classes, not for instances. In this case, setting the id should be kept out of __init__ since it is an instance initializer: make id static and thus getid() a classmethod. Furthermore, if yo

Re: Inheritance question

2008-03-25 Thread Gerard Flanagan
On Mar 25, 4:37 pm, Brian Lane <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > > > Gerard Flanagan wrote: > > Use the child class when calling super: > > > -- > > class Foo(object): > > def __init__(self): > > self.id

Re: Inheritance question

2008-03-25 Thread Eric Brunel
On Tue, 25 Mar 2008 16:37:00 +0100, Brian Lane <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > Gerard Flanagan wrote: > >> Use the child class when calling super: >> >> -- >> class Foo(object): >> def __init__(self): >>

  1   2   3   >