Re: class inheritance when not defined

2017-09-08 Thread Ben Finney
Steve D'Aprano writes: > Good way: > > Foreigner speaking English as their second language: > "Who is the father of this class?" > > Native English speaker: > "The father is 'object', but in English we would normally ask > 'what is the parent?' instead." Of the three scenario

Re: class inheritance when not defined

2017-09-08 Thread Steve D'Aprano
On Fri, 8 Sep 2017 07:03 pm, Ben Finney wrote: >> Who is the father of ExampleClass1 ? > > No-one, since classes do not have gender. (The convention is to use the > gender-neutral “parent” to refer to that relationship.) Possibly not the case in Russia. Besides, words have gender in many langua

Re: class inheritance when not defined

2017-09-08 Thread Ben Finney
Andrej Viktorovich writes: > I found several class creation samples: > > class ExampleClass1: > > class ExampleClass2(object): > > > What is difference between them? Very little difference. In Python 3, both create classes that inherit from one other class, ‘object’. In Python 2, the first cre

Re: class inheritance when not defined

2017-09-08 Thread Thomas Jollans
On 2017-09-08 10:17, Andrej Viktorovich wrote: > Hello > > I found several class creation samples: > > class ExampleClass1: > > class ExampleClass2(object): > > > What is difference between them? Who is the father of ExampleClass1 ? > In Python 3, unless you've redefined "object", these are

Re: Class Inheritance from different module

2014-09-22 Thread Jean-Michel Pichavant
- Original Message - > From: "Jean-Michel Pichavant" > To: "Juan Christian" > Cc: "Python" > Sent: Monday, 22 September, 2014 1:37:41 PM > Subject: Re: Class Inheritance from different module > > > > cl

Re: Class Inheritance from different module

2014-09-22 Thread Jean-Michel Pichavant
> class User(Inheritance from API): > def __init__(self, ID): > steamapi.core.APIConnection(api_key = KEY) > super( " Inheritance SteamUser" (ID)) # creates the user using the > API > > > [...] > > > So that in my code when I need to create a new user, I just call 'usr > = User("XXX")' ins

Re: Class Inheritance from different module

2014-09-20 Thread Peter Otten
Juan Christian wrote: > I have the following structure: > > Third-party API installed via pip: > steamapi / > app.py > consts.py > core.py > users.py > [...] > > My script: > test.py > > > In the API, the module users.py has a class 'SteamUser' and I want to > mimic it's usage on my code, like

Re: Class Inheritance from different module

2014-09-20 Thread Steven D'Aprano
Juan Christian wrote: [...] > In the API, the module users.py has a class 'SteamUser' and I want to > mimic it's usage on my code, like this: > > import steamapi > > [...] > > class User(Inheritance from API): What do you mean, "Inheritance from API"? You can't inherit from an API, only from c

Re: class inheritance python2.7 vs python3.3

2014-01-06 Thread jwe . van . dijk
On Monday, 6 January 2014 18:14:08 UTC+1, jwe.va...@gmail.com wrote: > I have problems with these two classes: > > > > class LPU1(): > > def __init__(self, formula): > > """ > > formula is a string that is parsed into a SymPy function > > and several derived func

Re: class inheritance python2.7 vs python3.3

2014-01-06 Thread Steven D'Aprano
jwe.van.d...@gmail.com wrote: > I have problems with these two classes: > > class LPU1(): > def __init__(self, formula): > """ > formula is a string that is parsed into a SymPy function > and several derived functions > """ > self.formula = formula >

Re: class inheritance python2.7 vs python3.3

2014-01-06 Thread Dave Angel
On Mon, 6 Jan 2014 09:14:08 -0800 (PST), jwe.van.d...@gmail.com wrote: I have problems with these two classes: class LPU1() : You forgot to derive from object. That's implied on 3.x, but you say you're also running on 2.7 Without naming your base class you're asking for an old style clas

Re: class inheritance python2.7 vs python3.3

2014-01-06 Thread Chris Angelico
On Tue, Jan 7, 2014 at 4:14 AM, wrote: > class LPU3(LPU1): > def __new__(self): > """ > the same functions as LPU1 but some added functions > and some functions redefined > """ You probably don't want to be using __new__ here. Try using __init__ instead, o

Re: class inheritance

2010-12-23 Thread JLundell
That's nice, Ethan, especially in that it saves having to explicitly find and list all the methods being covered. It's perhaps not quite so critical for a Fraction-based class, since the set of methods to be covered is fairly well contained, but that's not always going to be the case. The appro

Re: class inheritance

2010-12-21 Thread Ethan Furman
JLundell wrote: On Saturday, March 13, 2010 9:03:36 AM UTC-8, Jonathan Lundell wrote: I've got a subclass of fractions.Fraction called Value; it's a mostly trivial class, except that it overrides __eq__ to mean 'nearly equal'. However, since Fraction's operations result in a Fraction, not a Valu

Re: class inheritance

2010-12-17 Thread JLundell
On Saturday, March 13, 2010 9:03:36 AM UTC-8, Jonathan Lundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up

Re: class inheritance

2010-03-18 Thread JLundell
On Mar 17, 5:12 pm, Steven D'Aprano wrote: > On Mon, 15 Mar 2010 16:34:35 -0700,JLundellwrote: > > It's also unfortunate that Python doesn't have an approximately-equal > > operator; it'd come in handy for floating-point applications while > > preserving hash. If only there were a ~= or ≈ operator

Re: class inheritance

2010-03-17 Thread Steven D'Aprano
On Mon, 15 Mar 2010 16:34:35 -0700, JLundell wrote: > It's also unfortunate that Python doesn't have an approximately-equal > operator; it'd come in handy for floating-point applications while > preserving hash. If only there were a ~= or ≈ operator I could overload. > And ~ is unary, so no joy.

Re: class inheritance

2010-03-16 Thread Robert Kern
On 2010-03-16 17:55 PM, JLundell wrote: On Mar 16, 8:06 am, Robert Kern wrote: On 2010-03-16 07:35 AM, Dave Angel wrote: Carl Banks wrote: On Mar 15, 4:34 pm, JLundell wrote: It's also unfortunate that Python doesn't have an approximately-equal operator; it'd come in handy for floating-poi

Re: class inheritance

2010-03-16 Thread JLundell
On Mar 16, 8:06 am, Robert Kern wrote: > On 2010-03-16 07:35 AM, Dave Angel wrote: > > > > > > > > > Carl Banks wrote: > >> On Mar 15, 4:34 pm, JLundell wrote: > >>> It's also unfortunate that Python doesn't have an approximately-equal > >>> operator; it'd come in handy for floating-point applica

Re: class inheritance

2010-03-16 Thread Robert Kern
On 2010-03-16 07:35 AM, Dave Angel wrote: Carl Banks wrote: On Mar 15, 4:34 pm, JLundell wrote: It's also unfortunate that Python doesn't have an approximately-equal operator; it'd come in handy for floating-point applications while preserving hash. If only there were a ~=r ≈ operator I coul

Re: class inheritance

2010-03-16 Thread Dave Angel
Carl Banks wrote: On Mar 15, 4:34 pm, JLundell wrote: It's also unfortunate that Python doesn't have an approximately-equal operator; it'd come in handy for floating-point applications while preserving hash. If only there were a ~=r ≈ operator I could overload. And ~ is unary, so no joy.

Re: class inheritance

2010-03-15 Thread Carl Banks
On Mar 15, 4:34 pm, JLundell wrote: > It's also unfortunate that Python doesn't have an approximately-equal > operator; it'd come in handy for floating-point applications while > preserving hash. If only there were a ~= or ≈ operator I could > overload. And ~ is unary, so no joy. One problem with

Re: class inheritance

2010-03-15 Thread JLundell
On Mar 13, 1:26 pm, Carl Banks wrote: > It's a tad unfortunately Python doesn't make this easier.  If I had to > do it more than once I'd probably write a mixin to do it: > > class ArithmeticSelfCastMixin(object): >     def __add__(self,other): >         return > self.__class__(super(ArithmeticSel

Re: class inheritance

2010-03-15 Thread Jean-Michel Pichavant
JLundell wrote: I've got a subclass of fractions.Fraction called Value; it's a mostly trivial class, except that it overrides __eq__ to mean 'nearly equal'. However, since Fraction's operations result in a Fraction, not a Value, I end up with stuff like this: x = Value(1) + Value(2) where x is

Re: class inheritance

2010-03-13 Thread Carl Banks
On Mar 13, 9:03 am, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = Va

Re: class inheritance

2010-03-13 Thread JLundell
On Mar 13, 9:37 am, Jack Diederich wrote: > If Fraction.__add__ returns a new object but the subclass Value is > compatible (as I would except since it is a sublcass) then just change > all references in Franction.__add__ to be more generic, ex/ > > class Franction(): >   def __add__(self, other):

Re: class inheritance

2010-03-13 Thread Patrick Maupin
On Mar 13, 11:37 am, Jack Diederich wrote: > If Fraction.__add__ returns a new object but the subclass Value is > compatible (as I would except since it is a sublcass) then just change > all references in Franction.__add__ to be more generic, ex/ > > class Franction(): >   def __add__(self, other)

Re: class inheritance

2010-03-13 Thread Jack Diederich
On Sat, Mar 13, 2010 at 12:03 PM, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like th

Re: class inheritance

2010-03-13 Thread Patrick Maupin
On Mar 13, 11:03 am, JLundell wrote: > I've got a subclass of fractions.Fraction called Value; it's a mostly > trivial class, except that it overrides __eq__ to mean 'nearly equal'. > However, since Fraction's operations result in a Fraction, not a > Value, I end up with stuff like this: > > x = V

Re: Class Inheritance - What am I doing wrong?

2008-04-25 Thread Brian Munroe
On Apr 24, 10:11 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > In python, use attributes starting with a single underscore (such as > _name). It tells users that they shouldn't mess with them. By > design, python doesn't include mechanisms equivalent to the Java / C++ > 'private'. Arnaud, G

Re: Class Inheritance - What am I doing wrong?

2008-04-25 Thread Bruno Desthuilliers
Brian Munroe a écrit : Ok, so thanks everyone for the helpful hints. That *was* a typo on my part (should've been super(B...) not super(A..), but I digress) I'm building a public API. Along with the API I have a few custom types that I'm expecting API users to extend, if they need too. If I d

Re: Class Inheritance - What am I doing wrong?

2008-04-24 Thread Arnaud Delobelle
Brian Munroe <[EMAIL PROTECTED]> writes: > Ok, so thanks everyone for the helpful hints. That *was* a typo on my > part (should've been super(B...) not super(A..), but I digress) > > I'm building a public API. Along with the API I have a few custom > types that I'm expecting API users to extend,

Re: Class Inheritance - What am I doing wrong?

2008-04-24 Thread Gabriel Genellina
En Thu, 24 Apr 2008 18:18:01 -0300, Brian Munroe <[EMAIL PROTECTED]> escribió: Ok, so thanks everyone for the helpful hints. That *was* a typo on my part (should've been super(B...) not super(A..), but I digress) I'm building a public API. Along with the API I have a few custom types that I

Re: Class Inheritance - What am I doing wrong?

2008-04-24 Thread Brian Munroe
Ok, so thanks everyone for the helpful hints. That *was* a typo on my part (should've been super(B...) not super(A..), but I digress) I'm building a public API. Along with the API I have a few custom types that I'm expecting API users to extend, if they need too. If I don't use name mangling, i

Re: Class Inheritance - What am I doing wrong?

2008-04-24 Thread Gary Herron
Brian Munroe wrote: My example: class A(object): def __init__(self, name): self.__name = name def getName(self): return self.__name class B(A): def __init__(self,name=None): super(A,self).__init__() def setName(

Re: Class Inheritance - What am I doing wrong?

2008-04-24 Thread Arnaud Delobelle
Arnaud Delobelle <[EMAIL PROTECTED]> writes: > That is, if you also pass the name parameter to super(A,self).__init__ > in B's __init__ method Oops. should be super(B, self).__init__(name), of course. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Inheritance - What am I doing wrong?

2008-04-24 Thread Arnaud Delobelle
Brian Munroe <[EMAIL PROTECTED]> writes: > My example: > > class A(object): > > def __init__(self, name): > self.__name = name > > def getName(self): > return self.__name > > class B(A): > > def __init__(self,name=None): > super(A,self)._

Re: Class Inheritance - What am I doing wrong?

2008-04-24 Thread Virgil Dupras
On Apr 24, 10:22 pm, Brian Munroe <[EMAIL PROTECTED]> wrote: > My example: > > class A(object): > >         def __init__(self, name): >                 self.__name = name > >         def getName(self): >                 return self.__name > > class B(A): > >         def __init__(self,name=None): >

Re: Class Inheritance

2008-03-13 Thread Bruno Desthuilliers
Andrew Rekdal < a écrit : > I am trying to bring functions to a class by inheritance... for instance in > layout_ext I have.. > > > --- layout_ext.py- > class Layout() > def...some function that rely on css in Layout.py It shouldn't, definitively. The Layout instance should have a r

Re: Class Inheritance

2008-03-13 Thread Marc 'BlackJack' Rintsch
On Thu, 13 Mar 2008 00:06:52 -0500, "Andrew Rekdal" < wrote: > Problem is layout_ext and Layout code is dependant on a Class instance > 'css'. Then pass that instance to the `Layout` class in the `__init__()` so both, the base class and the subclass use the same `CSS` instance. Ciao, Ma