-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
> 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
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
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
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'
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-
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
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
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
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
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
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
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.
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
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
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 '
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
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
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'
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
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
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
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).
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
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)
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
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
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_
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:
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.
!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
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
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
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
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.
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):
>
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.
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
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
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'
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
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
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
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 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
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
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
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
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
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
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(
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
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
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
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
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
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
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
[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,
#
# 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
60 matches
Mail list logo