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

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

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

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

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,

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 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 = foo() c1.a = 5

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

Re: Class initialization

2010-08-08 Thread Tim Harig
On 2010-08-08, Costin Gament costin.gam...@gmail.com 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

Re: Class initialization

2010-08-08 Thread Jesse Jaggars
On Sun, Aug 8, 2010 at 10:01 AM, Tim Harig user...@ilthio.net wrote: On 2010-08-08, Costin Gament costin.gam...@gmail.com 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

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 user...@ilthio.net wrote: Others have told you

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 jhjagg...@gmail.com 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()

Re: Class initialization

2010-08-08 Thread Tim Harig
On 2010-08-08, Costin Gament costin.gam...@gmail.com 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

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 user...@ilthio.net 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

Re: Class initialization

2010-08-08 Thread Tim Harig
On 2010-08-08, Tim Harig user...@ilthio.net wrote: On 2010-08-08, Costin Gament costin.gam...@gmail.com 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

Re: Class initialization

2010-08-08 Thread Tim Harig
On 2010-08-08, Tim Harig user...@ilthio.net wrote: On 2010-08-08, Tim Harig user...@ilthio.net wrote: On 2010-08-08, Costin Gament costin.gam...@gmail.com 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

Re: Class initialization

2010-08-08 Thread Benjamin Kaplan
On Sun, Aug 8, 2010 at 6:32 AM, Costin Gament costin.gam...@gmail.com 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

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 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

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's the thing

Re: class initialization problem

2009-09-19 Thread Tim Roberts
rantingrick rantingr...@gmail.com 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

Re: class initialization problem

2009-09-18 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?

Re: class initialization problem

2009-09-18 Thread Gabriel Genellina
En Fri, 18 Sep 2009 03:12:46 -0300, rantingrick rantingr...@gmail.com 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

Re: class initialization problem

2009-09-18 Thread Dave Angel
rantingrick wrote: On Sep 18, 12:24 am, OKB (not okblacke) brennospamb...@nobrenspambarn.net 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

Re: class initialization problem

2009-09-17 Thread rantingrick
On Sep 17, 11:14 pm, alex23 wuwe...@gmail.com wrote: On Sep 18, 1:27 pm, rantingrick rantingr...@gmail.com 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):

Re: class initialization problem

2009-09-17 Thread Carl Banks
On Sep 17, 8:27 pm, rantingrick rantingr...@gmail.com 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__()

Re: class initialization problem

2009-09-17 Thread rantingrick
On Sep 17, 11:54 pm, Carl Banks pavlovevide...@gmail.com wrote: On Sep 17, 8:27 pm, rantingrick rantingr...@gmail.com 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

Re: class initialization problem

2009-09-17 Thread alex23
On Sep 18, 3:08 pm, rantingrick rantingr...@gmail.com 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

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 inherent

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 rantingrick
On Sep 18, 12:24 am, OKB (not okblacke) brennospamb...@nobrenspambarn.net 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

Re: class initialization problem

2009-09-17 Thread alex23
On Sep 18, 3:08 pm, rantingrick rantingr...@gmail.com 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

Re: class initialization problem

2009-09-17 Thread alex23
On Sep 18, 3:31 pm, alex23 wuwe...@gmail.com wrote: On Sep 18, 3:08 pm, rantingrick rantingr...@gmail.com 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

Re: class initialization problem

2009-09-17 Thread Carl Banks
On Sep 17, 10:08 pm, rantingrick rantingr...@gmail.com wrote: On Sep 17, 11:54 pm, Carl Banks pavlovevide...@gmail.com wrote: On Sep 17, 8:27 pm, rantingrick rantingr...@gmail.com wrote: ok i have a class and in it's constructor i want to create a copy of it as an attribute, i have

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

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 a

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's

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, class

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 that,

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-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 nice

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 the

Re: Proper class initialization

2006-03-02 Thread gry
= 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: @classmethod def init_class(self): sum = 0 for i in range(10): sum += i self.sum = sum

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)) I think

Proper class initialization

2006-03-01 Thread Christoph Zwerschke
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 work, I get

Re: Proper class initialization

2006-03-01 Thread Jack Diederich
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: Yes, it is called a meta class. class A: @classmethod def init_class(self): sum = 0

Re: Proper class initialization

2006-03-01 Thread Larry Bates
= 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: @classmethod def init_class(self): sum = 0 for i in range(10): sum += i self.sum = sum

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 --

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(10): sum += i self.sum

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
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 silly

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

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,