RE: Class initialization with multiple inheritance

2019-07-20 Thread Joseph L. Casale
-Original Message- From: Barry Scott Sent: Tuesday, July 16, 2019 11:53 AM To: Joseph L. Casale Cc: python-list@python.org Subject: Re: Class initialization with multiple inheritance > And here is the MRO for LeftAndRight. > > >>> import m > LeftAndRight.__ini

Re: Class initialization with multiple inheritance

2019-07-16 Thread Barry Scott
> On 16 Jul 2019, at 01:13, Joseph L. Casale wrote: > > I am trying to find explicit documentation on the initialization logic for a > Base class when multiple exist. For the example in the documentation at > https://docs.python.org/3/tutorial/classes.html#multiple-inheritance, > if Base1 and

Re: Class initialization with multiple inheritance

2019-07-15 Thread DL Neil
On 16/07/19 12:13 PM, Joseph L. Casale wrote: I am trying to find explicit documentation on the initialization logic for a Base class when multiple exist. For the example in the documentation at https://docs.python.org/3/tutorial/classes.html#multiple-inheritance, if Base1 and Base2 both themselv

Class initialization with multiple inheritance

2019-07-15 Thread Joseph L. Casale
I am trying to find explicit documentation on the initialization logic for a Base class when multiple exist. For the example in the documentation at https://docs.python.org/3/tutorial/classes.html#multiple-inheritance, if Base1 and Base2 both themselves inherited from the same base class, only Base

Re: Class initialization

2010-08-08 Thread Steven D'Aprano
On Sun, 08 Aug 2010 19:47:18 -0400, Mel wrote: > Costin Gament wrote: > >> So you're saying I should just use __init__? Will that get me out of my >> predicament? >> No, I don't quite understand the difference between my exemple and >> using __init__, but I will read the docs about it. > > Here'

Re: Class initialization

2010-08-08 Thread Mel
Costin Gament wrote: > So you're saying I should just use __init__? Will that get me out of > my predicament? > No, I don't quite understand the difference between my exemple and > using __init__, but I will read the docs about it. Here's the thing about class variables: Python 2.6.2 (release26-

Re: Class initialization

2010-08-08 Thread Costin Gamenț
Thank you all for your answers and your patience. As soon as I can, I'll update my code and read up on the subject. If I still can't get it working, I'll bother you again. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class initialization

2010-08-08 Thread Benjamin Kaplan
On Sun, Aug 8, 2010 at 6:32 AM, Costin Gament wrote: > > Hi there. > I'm kind of a beginner with Python (and programming in general). My > problem is with initializing a class. Let's say I've defined it like > this: > > class foo: >   a = 0 >   b = 0 > > and later I'm trying to initialize two diff

Re: Class initialization

2010-08-08 Thread Tim Harig
On 2010-08-08, Tim Harig wrote: > On 2010-08-08, Tim Harig wrote: >> On 2010-08-08, Costin Gament wrote: >>> So you're saying I should just use __init__? Will that get me out of >>> my predicament? >>> No, I don't quite understand the difference between my exemple and >>> using __init__, but I w

Re: Class initialization

2010-08-08 Thread Tim Harig
On 2010-08-08, Tim Harig wrote: > On 2010-08-08, Costin Gament wrote: >> So you're saying I should just use __init__? Will that get me out of >> my predicament? >> No, I don't quite understand the difference between my exemple and >> using __init__, but I will read the docs about it. > > It is no

Re: Class initialization

2010-08-08 Thread Costin Gamenț
Thanks a lot. I'll try give it a go and see if it helps. On Sun, Aug 8, 2010 at 6:28 PM, Tim Harig wrote: > It is not so much using __init__() that makes the difference as it what > scope the variables are assigned to.  If you define them as you where, then > the variables are associated with the

Re: Class initialization

2010-08-08 Thread Tim Harig
On 2010-08-08, Costin Gament wrote: > So you're saying I should just use __init__? Will that get me out of > my predicament? > No, I don't quite understand the difference between my exemple and > using __init__, but I will read the docs about it. It is not so much using __init__() that makes the

Re: Class initialization

2010-08-08 Thread Costin Gament
That looks just like my code. What's the problem? On Sun, Aug 8, 2010 at 6:13 PM, Jesse Jaggars wrote: > > Is it possible that you are using a mutable class object? A common > gotcha is to do something like this: > class foo(object): > ...   x = [] > ... a = foo() b = foo() a.

Re: Class initialization

2010-08-08 Thread Costin Gament
So you're saying I should just use __init__? Will that get me out of my predicament? No, I don't quite understand the difference between my exemple and using __init__, but I will read the docs about it. On Sun, Aug 8, 2010 at 6:01 PM, Tim Harig wrote: > > Others have told you that at a and b belo

Re: Class initialization

2010-08-08 Thread Jesse Jaggars
On Sun, Aug 8, 2010 at 10:01 AM, Tim Harig wrote: > On 2010-08-08, Costin Gament wrote: >> Thank you for your answer, but it seems I didn't make myself clear. >> Take the code: >> class foo: >>   a = 0 >>   b = 0 >> c1 = foo() >> c1.a = 5 >> c2 = foo() >> print c2.a >> 5 >> >> Somehow, when I try

Re: Class initialization

2010-08-08 Thread Tim Harig
On 2010-08-08, Costin Gament wrote: > Thank you for your answer, but it seems I didn't make myself clear. > Take the code: > class foo: > a = 0 > b = 0 > c1 = foo() > c1.a = 5 > c2 = foo() > print c2.a > 5 > > Somehow, when I try to acces the 'a' variable in c2 it has the same > value as the '

Re: Class initialization

2010-08-08 Thread Costin Gament
Apparently, the code I've given here does, in fact, work. Still, I am encountering a similar problem in a much larger class (it is in a separate module, if that is any help). Also, the variable I am having trouble with is itself another class. I don't think it's appropriate to paste so much code in

Re: Class initialization

2010-08-08 Thread Steven D'Aprano
On Sun, 08 Aug 2010 17:14:08 +0300, Costin Gament wrote: > Thank you for your answer, but it seems I didn't make myself clear. Take > the code: > class foo: > a = 0 > b = 0 > c1 = foo() > c1.a = 5 > c2 = foo() > print c2.a > 5 Incorrect. >>> class foo: ... a = 0 ... b = 0 ... >>> c1 = fo

Re: Class initialization

2010-08-08 Thread Roald de Vries
On Aug 8, 2010, at 4:14 PM, Costin Gament wrote: Thank you for your answer, but it seems I didn't make myself clear. You could have been clearer in your first post, yeah. Take the code: class foo: a = 0 b = 0 c1 = foo() c1.a = 5 c2 = foo() print c2.a 5 Somehow, when I try to acces the 'a'

Re: Class initialization

2010-08-08 Thread Costin Gament
Thank you for your answer, but it seems I didn't make myself clear. Take the code: class foo: a = 0 b = 0 c1 = foo() c1.a = 5 c2 = foo() print c2.a 5 Somehow, when I try to acces the 'a' variable in c2 it has the same value as the 'a' variable in c1. Am I missing something? On Sun, Aug 8, 201

Re: Class initialization

2010-08-08 Thread Roald de Vries
On Aug 8, 2010, at 3:32 PM, Costin Gament wrote: Hi there. I'm kind of a beginner with Python (and programming in general). My problem is with initializing a class. Let's say I've defined it like this: class foo: a = 0 b = 0 and later I'm trying to initialize two different classes like this

Class initialization

2010-08-08 Thread Costin Gament
Hi there. I'm kind of a beginner with Python (and programming in general). My problem is with initializing a class. Let's say I've defined it like this: class foo: a = 0 b = 0 and later I'm trying to initialize two different classes like this: c1 = foo() c2 = foo() The problem I have is th

Re: class initialization problem

2009-09-19 Thread Tim Roberts
rantingrick wrote: > >WHY did i need do this you may ask? >I am creating geometry with OpenGL. When you create a face you must >specify a winding order (clockwise or counter clockwise) this winding >order controls which side of the face will be visible (since only one >side of a face is rendered).

Re: class initialization problem

2009-09-18 Thread Dave Angel
rantingrick wrote: On Sep 18, 12:24 am, "OKB (not okblacke)" wrote: Perhaps you want to cut off the recursion at the first step, so that the nested instance itself does not have a nested instance. If so, add another parameter to __init__ that flags whether you are creating a "top-le

Re: class initialization problem

2009-09-17 Thread Gabriel Genellina
En Fri, 18 Sep 2009 03:12:46 -0300, rantingrick escribió: I am creating geometry with OpenGL. When you create a face you must specify a winding order (clockwise or counter clockwise) this winding order controls which side of the face will be visible (since only one side of a face is rendered)

Re: class initialization problem

2009-09-17 Thread rantingrick
EDIT: copy.copy did work in a simple python interactive session, but it caused infinite recursion in my real world code? Anyway what ever is going on (probably lack of sleep!) the cure all was using an arg in the initial function. So now i am good as gold ;-) WHY did i need do this you may ask? I

Re: class initialization problem

2009-09-17 Thread Carl Banks
On Sep 17, 10:08 pm, rantingrick wrote: > On Sep 17, 11:54 pm, Carl Banks wrote: > > > > > > > On Sep 17, 8:27 pm, rantingrick wrote: > > > > ok i have a class and in it's constructor i want to create a copy of > > > it as an attribute, i have tried super, __new__, and noting seems to > > > work

Re: class initialization problem

2009-09-17 Thread alex23
On Sep 18, 3:31 pm, alex23 wrote: > On Sep 18, 3:08 pm, rantingrick wrote: > > > ok here is some code. this will cause an infinite recursion. > > > class A(): > >     def __init__(self, *args): > >         self.nestedA = A(*args) #NO GOOD! > > How about: > >   class A(object): >       def __init_

Re: class initialization problem

2009-09-17 Thread alex23
On Sep 18, 3:08 pm, rantingrick wrote: > ok here is some code. this will cause an infinite recursion. > > class A(): >     def __init__(self, *args): >         self.nestedA = A(*args) #NO GOOD! How about: class A(object): def __init__(self, first=True, *args): if first:

Re: class initialization problem

2009-09-17 Thread rantingrick
On Sep 18, 12:24 am, "OKB (not okblacke)" wrote: >         Perhaps you want to cut off the recursion at the first step, so > that the nested instance itself does not have a nested instance.  If so, > add another parameter to __init__ that flags whether you are creating a > "top-level" instance.

Re: class initialization problem

2009-09-17 Thread rantingrick
!SOLVED! Thanks for the help guys! copy.copy did it! Why does me makes life so hard on me? ;-) -- http://mail.python.org/mailman/listinfo/python-list

Re: class initialization problem

2009-09-17 Thread OKB (not okblacke)
rantingrick wrote: > ok here is some code. this will cause an infinite recursion. > > class A(): > def __init__(self, *args): > self.nestedA = A(*args) #NO GOOD! > > there must be a way to create an instance of an object within the > same objects constructor? This is an inhe

Re: class initialization problem

2009-09-17 Thread alex23
On Sep 18, 3:08 pm, rantingrick wrote: > ok here is some code. this will cause an infinite recursion. > > class A(): >     def __init__(self, *args): >         self.nestedA = A(*args) #NO GOOD! > > there must be a way to create an instance of an object within the same > objects constructor? But i

Re: class initialization problem

2009-09-17 Thread rantingrick
On Sep 17, 11:54 pm, Carl Banks wrote: > On Sep 17, 8:27 pm, rantingrick wrote: > > > ok i have a class and in it's constructor i want to create a copy of > > it as an attribute, i have tried super, __new__, and noting seems to > > work, please help! > > > class A(base): > >     def __init__(self

Re: class initialization problem

2009-09-17 Thread Carl Banks
On Sep 17, 8:27 pm, rantingrick wrote: > ok i have a class and in it's constructor i want to create a copy of > it as an attribute, i have tried super, __new__, and noting seems to > work, please help! > > class A(base): >     def __init__(self): >         super(A, self).__init__() >         self.

Re: class initialization problem

2009-09-17 Thread rantingrick
On Sep 17, 11:14 pm, alex23 wrote: > On Sep 18, 1:27 pm, rantingrick wrote: > > > ok i have a class and in it's constructor i want to create a copy of > > it as an attribute, i have tried super, __new__, and noting seems to > > work, please help! > > > class A(base): > >     def __init__(self): >

Re: class initialization problem

2009-09-17 Thread alex23
On Sep 18, 1:27 pm, rantingrick wrote: > ok i have a class and in it's constructor i want to create a copy of > it as an attribute, i have tried super, __new__, and noting seems to > work, please help! > > class A(base): >     def __init__(self): >         super(A, self).__init__() >         self.

class initialization problem

2009-09-17 Thread rantingrick
ok i have a class and in it's constructor i want to create a copy of it as an attribute, i have tried super, __new__, and noting seems to work, please help! class A(base): def __init__(self): super(A, self).__init__() self.nested = ? think of a nested list [ [] ] but with obje

Re: Static Class Initialization Question.

2008-07-04 Thread Marc 'BlackJack' Rintsch
On Fri, 04 Jul 2008 14:59:05 +0200, Thomas Troeger wrote: > Bruno Desthuilliers wrote: >>> I want to have a list of such classes instantiated automatically on > > Of course I meant class instances ... sorry :) It's always good to have > an example to compensate for English errors *g*. Well, "c

Re: Static Class Initialization Question.

2008-07-04 Thread Thomas Troeger
Bruno Desthuilliers wrote: return "%s(%d,%d)" % (type(self).__name__, self.a, self.b) Er, yes exactly! I noticed it a few seconds after I had sent the message ;-( I want to have a list of such classes instantiated automatically on Of course I meant class instances ... sorry :) It'

Re: Static Class Initialization Question.

2008-07-04 Thread Bruno Desthuilliers
Thomas Troeger a écrit : Hello, I have a class that looks like this: class A(object): def __init__(self, a=0, b=1): self.a, self.b=a, b def __str__(self): return "%s(%d,%d)" % (type(a).__name__, self.a, self.b) Given the output example you give, I assume there's

Static Class Initialization Question.

2008-07-04 Thread Thomas Troeger
Hello, I have a class that looks like this: class A(object): def __init__(self, a=0, b=1): self.a, self.b=a, b def __str__(self): return "%s(%d,%d)" % (type(a).__name__, self.a, self.b) I want to have a list of such classes instantiated a

Re: Proper class initialization

2006-03-03 Thread Christoph Zwerschke
gry@ll.mit.edu schrieb: > Hmm, the meta-class hacks mentioned are cool, but for this simple a > case how about just: > > class A: >def __init__(self): > self.__class__.sum = self.calculate_sum() >def calculate_sum(self): > do_stuff > return sum_value If you do it like th

Re: Proper class initialization

2006-03-02 Thread Steven Bethard
Kent Johnson wrote: > Steven Bethard wrote: >> I don't run into this often, but when I do, I usually go Jack >> Diederich's route:: >> >> class A(object): >> class __metaclass__(type): >> def __init__(cls, name, bases, classdict): >> cls.sum = sum(xrange(10)

Re: Proper class initialization

2006-03-02 Thread gry
I could call a function external to the class > > def calc_sum(n): > ... > > class A: > sum = calc_sum(10) > > But I wonder whether it is possible to put all this init code into one > class initialization method, something like that: > > class A: > > @classm

Re: Proper class initialization

2006-03-02 Thread Kent Johnson
Steven Bethard wrote: > I don't run into this often, but when I do, I usually go Jack > Diederich's route:: > > class A(object): > class __metaclass__(type): > def __init__(cls, name, bases, classdict): > cls.sum = sum(xrange(10)) I think you should call t

Re: Proper class initialization

2006-03-02 Thread Christoph Zwerschke
Steven Bethard wrote: > I don't run into this often, but when I do, I usually go Jack > Diederich's route:: > > class A(object): > class __metaclass__(type): > def __init__(cls, name, bases, classdict): > cls.sum = sum(xrange(10)) Good idea, that is really

Re: Proper class initialization

2006-03-02 Thread Christoph Zwerschke
Steven Bethard wrote: > I assume the intention was to indicate that the initialization required > multiple statements. I just couldn't bring myself to write that > horrible for-loop when the sum() function is builtin. ;) Yes, this was just dummy code standing for something that really requires

Re: Proper class initialization

2006-03-01 Thread Steven Bethard
Leif K-Brooks wrote: > Steven Bethard wrote: >> class A(object): >> def _get_sum(): >> return sum(xrange(10)) >> sum = _get_sum() > > What's wrong with sum = sum(xrange(10))? Nothing, except that it probably doesn't answer the OP's question. The OP presented a "s

Re: Proper class initialization

2006-03-01 Thread Leif K-Brooks
Steven Bethard wrote: > class A(object): > def _get_sum(): > return sum(xrange(10)) > sum = _get_sum() What's wrong with sum = sum(xrange(10))? -- http://mail.python.org/mailman/listinfo/python-list

Re: Proper class initialization

2006-03-01 Thread Steven Bethard
Christoph Zwerschke wrote: > But I wonder whether it is possible to put all this init code into one > class initialization method, something like that: > > class A: > > @classmethod > def init_class(self): > sum = 0 > for i in range(

Re: Proper class initialization

2006-03-01 Thread Christoph Zwerschke
Jack Diederich wrote: > ... __metaclass__ = MyMeta Thanks. I was not aware of the __metaclass__ attribute. Still a bit complicated and as you said, difficult to read, as the other workarounds already proposed. Anyway, this is probably not needed so often. -- Christoph -- http://mail.python.o

Re: Proper class initialization

2006-03-01 Thread Larry Bates
could call a function external to the class > > def calc_sum(n): > ... > > class A: > sum = calc_sum(10) > > But I wonder whether it is possible to put all this init code into one > class initialization method, something like that: > > class A: > > @classme

Re: Proper class initialization

2006-03-01 Thread Jack Diederich
ch is not desired. > > Of course, I could call a function external to the class > > def calc_sum(n): > ... > > class A: > sum = calc_sum(10) > > But I wonder whether it is possible to put all this init code into one > class initialization method, somethin

Proper class initialization

2006-03-01 Thread Christoph Zwerschke
ther it is possible to put all this init code into one class initialization method, something like that: class A: @classmethod def init_class(self): sum = 0 for i in range(10): sum += i self.sum = sum init_class() However, this does not w

Re: Class initialization from a dictionary, how best?

2005-01-14 Thread Bengt Richter
On 14 Jan 2005 07:32:06 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: >Yes, my examle here is a tiny part of a larger more complex issue. My >application is an DOM XML parser that is reading attributes one at a you mean like blah blah and you are grabbing things of interest out of a stream

Re: Class initialization from a dictionary, how best?

2005-01-14 Thread [EMAIL PROTECTED]
Yes, my examle here is a tiny part of a larger more complex issue. My application is an DOM XML parser that is reading attributes one at a time. My class that I am creating is used elsewhere and must have certain arguments for those uses to continue working. So, I seem to be left with creating an i

Re: Class initialization from a dictionary, how best?

2005-01-14 Thread Bengt Richter
On 13 Jan 2005 20:36:19 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: ># ># My problem is that I want to create a ># class, but the variables aren't known ># all at once. So, I use a dictionary to ># store the values in temporarily. Why? ># Then when I have a complete set, I want to ># ini

Re: Class initialization from a dictionary, how best?

2005-01-13 Thread Nick Coghlan
[EMAIL PROTECTED] wrote: t2 = Test(dictionary.get('a'), dictionary.get('b'), dictionary.get('c')) print t2 Try this: t2 = Test(**dictionary) This performs keyword argument expansion on the dictionary, matching the dictionary entries with the named arguments to the Test.__init__ function. Cheers,

Class initialization from a dictionary, how best?

2005-01-13 Thread [EMAIL PROTECTED]
# # My problem is that I want to create a # class, but the variables aren't known # all at once. So, I use a dictionary to # store the values in temporarily. # Then when I have a complete set, I want to # init a class from that dictionary. # However, I don't want to specify the # dictionary gets by