-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
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
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
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
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,
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'
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
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
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
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
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
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()
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
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
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
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
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
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
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
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
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
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?
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
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
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):
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__()
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
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
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
!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
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
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
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
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
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
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
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
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
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,
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
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
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
= 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
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
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
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
= 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
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
--
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
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
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
#
# 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
[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,
55 matches
Mail list logo