On 18 October 2012 15:10, Jeff Jeffries jeff.jeffries@gmail.com wrote:
Hello everybody
When I set AttributeChanges in my example, it sets the same value for all
other subclasses. Can someone help me with what the name of this behavior is
(mutable class global?) ? I don't know any
On 10/18/2012 10:10 AM, Jeff Jeffries wrote:
Hello everybody
When I set AttributeChanges in my example, it sets the same value for all
other subclasses. Can someone help me with what the name of this behavior
is (mutable class global?) ? I don't know any keywords... having
trouble
On Thu, Oct 18, 2012 at 10:51 AM, Dave Angel d...@davea.name wrote:
On 10/18/2012 10:10 AM, Jeff Jeffries wrote:
Hello everybody
When I set AttributeChanges in my example, it sets the same value for
all
other subclasses. Can someone help me with what the name of this behavior
is
On Tue, 31 Mar 2009 01:29:50 -0300, Gabriel Genellina wrote:
Oh, and while the gurus are at it, what would be the advantage (if any)
of changing, say
Primate.__init__(self)
to
super(Human, self).__init__()
None, if you use single inheritance everywhere.
But there's no
On Mar 31, 5:13 am, Nick mediocre_per...@hotmail.com wrote:
Oh, and while the gurus are at it, what would be the advantage (if any) of
changing, say
Primate.__init__(self)
to
super(Human, self).__init__()
What others said. In Python 3.0 you would have a bigger advantage,
since you
Thanks for the replies. This has given me some incentive to start looking at
Python 3. Oh, and thanks for the articles on super().
Nick
--
http://mail.python.org/mailman/listinfo/python-list
En Tue, 31 Mar 2009 05:16:47 -0300, Steven D'Aprano
ste...@remove.this.cybersource.com.au escribió:
On Tue, 31 Mar 2009 01:29:50 -0300, Gabriel Genellina wrote:
Oh, and while the gurus are at it, what would be the advantage (if any)
of changing, say
Primate.__init__(self)
to
I've got a collection of classes describing animals, part of which looks
like:
class Animal(object):
def __init__(self):
self.pet = False
self.edible = False
self.legs = 0
self.sound = None
self.name = self.__class__.__name__.lower()
class Mammal(Animal):
En Tue, 31 Mar 2009 00:13:44 -0300, Nick mediocre_per...@hotmail.com
escribió:
I've got a collection of classes describing animals, part of which looks
like:
class Animal(object):
def __init__(self):
self.pet = False
self.edible = False
self.legs = 0
On Mar 31, 1:13 pm, Nick mediocre_per...@hotmail.com wrote:
I want to add a pedigree function to Animal so that I can have:
h = Human()
h.pedigree()
human primate mammal animal
class Animal(object):
@classmethod
def pedigree(cls):
return [c.__name__ for c in cls.mro()
Preamble: when posting a brand new question, you'd better not replying to
an existing completely unrelated message. In most viewers, this will cause
your message to appear in the thread for the original question and far
less people will see it. So better create a brand new thread.
On Fri,
I have this class:
class Vector(object):
TOL = 1e-5
def __eq__( self, other, tolerance=TOL ):
print tolerance
shortened for clarity obviously. so I want to subclass this class like
so:
class BigVector(Vector)
TOL = 100
for example if I was working with large
On Fri, Jun 20, 2008 at 6:19 PM, Hamish McKenzie
[EMAIL PROTECTED] wrote:
I have this class:
class Vector(object):
TOL = 1e-5
def __eq__( self, other, tolerance=TOL ):
print tolerance
shortened for clarity obviously. so I want to subclass this class like
so:
class
given two classes:
class Foo(object):
def __init__(self):
self.id = 1
def getid(self):
return self.id
class FooSon(Foo):
def __init__(self):
Foo.__init__(self)
self.id = 2
def getid(self):
a = Foo.getid()
b = self.id
Rather than use Foo.bar(), use this syntax to call methods of the
super class:
super(ParentClass, self).method()
--
http://mail.python.org/mailman/listinfo/python-list
On Mar 25, 10:44 pm, Tzury Bar Yochay [EMAIL PROTECTED] wrote:
given two classes:
class Foo(object):
def __init__(self):
self.id = 1
def getid(self):
return self.id
class FooSon(Foo):
def __init__(self):
Foo.__init__(self)
self.id = 2
On Mar 25, 2:00 pm, John Machin [EMAIL PROTECTED] wrote:
On Mar 25, 10:44 pm, Tzury Bar Yochay [EMAIL PROTECTED] wrote:
given two classes:
class Foo(object):
def __init__(self):
self.id = 1
def getid(self):
return self.id
class FooSon(Foo):
def
Rather than use Foo.bar(), use this syntax to call methods of the
super class:
super(ParentClass, self).method()
Hi Jeff,
here is the nw version which cause an error
class Foo(object):
def __init__(self):
self.id = 1
def getid(self):
return self.id
class
a = super(Foo, self).getid()
should be
a = super(FooSon, self).getid()
On Tue, Mar 25, 2008 at 2:34 PM, Tzury Bar Yochay [EMAIL PROTECTED]
wrote:
Rather than use Foo.bar(), use this syntax to call methods of the
super class:
super(ParentClass, self).method()
Hi Jeff,
here is the nw
In the derived class init you set self.id to 2 so
when you call getid method it just returns self.id which is now 2.
you can use another variable name.
On Tue, Mar 25, 2008 at 1:44 PM, Tzury Bar Yochay [EMAIL PROTECTED]
wrote:
given two classes:
class Foo(object):
def __init__(self):
On Mar 25, 11:44 am, Tzury Bar Yochay [EMAIL PROTECTED] wrote:
While my intention is to get 1.2 I get 2.2
I would like to know what would be the right way to yield the expected
results
Is this what you want?
class Foo(object):
def __init__(self):
self.id = 1
def getid(self):
On Mar 25, 4:03 pm, Anthony [EMAIL PROTECTED] wrote:
On Mar 25, 11:44 am, Tzury Bar Yochay [EMAIL PROTECTED] wrote:
While my intention is to get 1.2 I get 2.2
I would like to know what would be the right way to yield the expected
results
Is this what you want?
class Foo(object):
On Mar 25, 1:34 pm, Tzury Bar Yochay [EMAIL PROTECTED] wrote:
Rather than use Foo.bar(), use this syntax to call methods of the
super class:
super(ParentClass, self).method()
Hi Jeff,
here is the nw version which cause an error
class Foo(object):
def __init__(self):
On Mar 25, 2:31 pm, Tzury Bar Yochay [EMAIL PROTECTED] wrote:
I wish it was that simple but 'a = Foo().getid()' is actually creating
a new instance of Foo whereas I want the data of the Foo instanced by
__init__ of FooSon().
I don't think Foo.__init__(self) creates an instance of the Foo
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Gerard Flanagan wrote:
Use the child class when calling super:
--
class Foo(object):
def __init__(self):
self.id = 1
def getid(self):
return self.id
class FooSon(Foo):
def
Tzury Bar Yochay [EMAIL PROTECTED] writes:
given two classes:
class Foo(object):
def __init__(self):
self.id = 1
def getid(self):
return self.id
class FooSon(Foo):
def __init__(self):
Foo.__init__(self)
self.id = 2
def getid(self):
Brian Lane [EMAIL PROTECTED] writes:
Basically, you can't do what you are trying to do without using a
different variable,
...or abusing the __foo private identifier trick.
--
http://mail.python.org/mailman/listinfo/python-list
Anthony wrote:
On Mar 25, 2:31 pm, Tzury Bar Yochay [EMAIL PROTECTED] wrote:
I wish it was that simple but 'a = Foo().getid()' is actually creating
a new instance of Foo whereas I want the data of the Foo instanced by
__init__ of FooSon().
I don't think Foo.__init__(self) creates an
On Tue, 25 Mar 2008 16:37:00 +0100, Brian Lane [EMAIL PROTECTED] wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Gerard Flanagan wrote:
Use the child class when calling super:
--
class Foo(object):
def __init__(self):
self.id = 1
On Mar 25, 4:37 pm, Brian Lane [EMAIL PROTECTED] wrote:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Gerard Flanagan wrote:
Use the child class when calling super:
--
class Foo(object):
def __init__(self):
self.id = 1
def
Hi,
I'm not sure what you're trying to actually achieve, but it seems that
you want an identificator for classes, not for instances. In this case,
setting the id should be kept out of __init__ since it is an instance
initializer: make id static and thus getid() a classmethod.
Furthermore, if
On Mar 25, 12:01 pm, Robert Bossy [EMAIL PROTECTED] wrote:
Hi,
I'm not sure what you're trying to actually achieve, but it seems that
you want an identificator for classes, not for instances. In this case,
setting the id should be kept out of __init__ since it is an instance
initializer:
Hi all,
I would like to thank you all for all the suggestions.
what I did was simply extending the super class data with data from
its child
using the id example, Foo.id = 1 is now = [1] and the FooSon does
self.id.append(2)
the system designer wanted inheritance+java and I wanted Python
Lie a écrit :
On Jan 16, 9:23 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
Lie wrote:
[EMAIL PROTECTED] wrote:
I used to systematically use it - like I've always systematically
used 'this' in C++ and Java.
And that is what reduces readability.
IMHO not, IOPHO not. This is the
Please stop taking my words to its letters.
So we're supposed to actually guess what you really mean ???
That's what human does, otherwise you'll Fail the Turing Test.
Personally, I've seen many C++ programs with complex class designs
where it definitely helps to consistently use this-.
(messed up references?)
Lie wrote:
Please again, stop taking letters to the words
Please don't mix up followups.
Regards,
Björn
--
BOFH excuse #11:
magnetic interference from money/credit cards
--
http://mail.python.org/mailman/listinfo/python-list
On Jan 16, 9:23 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
Lie wrote:
[EMAIL PROTECTED] wrote:
I used to systematically use it - like I've always systematically
used 'this' in C++ and Java.
And that is what reduces readability.
IMHO not, IOPHO not. This is the nth time
On Jan 15, 9:00 pm, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:
Lie a écrit :
On Jan 7, 2:46 am, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
Lie a écrit :
On Jan 5, 5:40 pm, [EMAIL PROTECTED] wrote:
Jeroen Ruigrok van der Werven wrote:
Shouldn't this be:
self.startLoc =
Lie wrote:
[EMAIL PROTECTED] wrote:
I used to systematically use it - like I've always systematically
used 'this' in C++ and Java.
And that is what reduces readability.
IMHO not, IOPHO not. This is the nth time (n 1) this discussion
comes up here. If I have learned one thing from those
Lie a écrit :
On Jan 15, 9:00 pm, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:
Lie a écrit :
On Jan 7, 2:46 am, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
Lie a écrit :
(snip)
No, seriously it isn't Java habits only, most other languages wouldn't
need explicit calling of class
Lie a écrit :
On Jan 7, 2:46 am, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
Lie a écrit :
On Jan 5, 5:40 pm, [EMAIL PROTECTED] wrote:
Jeroen Ruigrok van der Werven wrote:
Shouldn't this be:
self.startLoc = start
self.stopLoc = stop
Thanks! Of course it should. Old Java habits die
On Jan 7, 2:46 am, Bruno Desthuilliers
[EMAIL PROTECTED] wrote:
Lie a écrit :
On Jan 5, 5:40 pm, [EMAIL PROTECTED] wrote:
Jeroen Ruigrok van der Werven wrote:
Shouldn't this be:
self.startLoc = start
self.stopLoc = stop
Thanks! Of course it should. Old Java habits die slowly.
No,
Lie a écrit :
On Jan 5, 5:40 pm, [EMAIL PROTECTED] wrote:
Jeroen Ruigrok van der Werven wrote:
Shouldn't this be:
self.startLoc = start
self.stopLoc = stop
Thanks! Of course it should. Old Java habits die slowly.
No, seriously it isn't Java habits only, most other languages wouldn't
On Jan 5, 2008 11:31 AM, [EMAIL PROTECTED] wrote:
import tok
class code:
def __init__( self, start, stop ):
startLoc = start
stopLoc = stop
class token(code):
pass
Apart from the missing self, remember that the __init__(...) of the
base classes is not
On Jan 5, 4:53 am, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
[EMAIL PROTECTED] wrote:
Jeroen Ruigrok van der Werven wrote:
self.startLoc = start
self.stopLoc = stop
Thanks! Of course it should. Old Java habits die slowly.
That's not really a Java habit. In Java and C++,
On Jan 6, 2008 6:59 PM, Dan Bishop [EMAIL PROTECTED] wrote:
My employer has us use the m_ convention.
I wonder why Bjarne made this- optional in the first place.
--
http://mail.python.org/mailman/listinfo/python-list
I think implicit this- is somewhat more defensible. If 'this' were not a
Working on parser for my language, I see that all classes (Token,
Production, Statement, ...) have one thing in common. They all
maintain start and stop positions in the source text. So it seems
logical to have them all inherit from a base class that defines those,
but this doesn't work:
import
-On [20080105 11:36], [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote:
class code:
def __init__( self, start, stop ):
startLoc = start
stopLoc = stop
Shouldn't this be:
self.startLoc = start
self.stopLoc = stop
?
--
Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org /
On Jan 5, 10:31 am, [EMAIL PROTECTED] wrote:
...
class code:
def __init__( self, start, stop ):
startLoc = start
stopLoc = stop
...
You've forgotten the explicit self.
def __init__( self, start, stop ):
self.startLoc = start
self.stopLoc = stop
--
Jeroen Ruigrok van der Werven wrote:
Shouldn't this be:
self.startLoc = start
self.stopLoc = stop
Thanks! Of course it should. Old Java habits die slowly.
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] wrote:
Jeroen Ruigrok van der Werven wrote:
self.startLoc = start
self.stopLoc = stop
Thanks! Of course it should. Old Java habits die slowly.
That's not really a Java habit. In Java and C++, personally I like
to write
this.startLoc = start
this.stopLoc = stop
It makes
On Jan 5, 5:40 pm, [EMAIL PROTECTED] wrote:
Jeroen Ruigrok van der Werven wrote:
Shouldn't this be:
self.startLoc = start
self.stopLoc = stop
Thanks! Of course it should. Old Java habits die slowly.
No, seriously it isn't Java habits only, most other languages wouldn't
need explicit
Gabriel Genellina wrote:
At Saturday 11/11/2006 03:31, Frank Millman wrote:
Continuing your analogy of animals, assume a class A with a 'walk'
method and an 'eat' method.
Most animals walk the same way, but a few don't, so I create a subclass
AW and override the walk method.
Most
Jackson wrote:
For a more concrete example:
Suppose all the animals in the world have only 1 or 2 legs.
class Legs(object)
def run(): pass
def walk(number_of_legs):
# lots of commands
# that do not depend on the
# number of legs but definitely
# have to do with
I've got an inheritance question and was hoping brighter minds could
guide me. I am in the strange situation where some of the methods in a
subclass are actually more general than methods in a superclass. What
is the preferred way to handle such situations. My original thought was
to do
At Friday 10/11/2006 21:13, Jackson wrote:
I've got an inheritance question and was hoping brighter minds could
guide me. I am in the strange situation where some of the methods in a
subclass are actually more general than methods in a superclass. What
is the preferred way to handle
Gabriel Genellina wrote:
If walking in general, have some common structure, you can put the
sketch on Legs and let the derived classes fill the gaps. This is
known as Template Method Pattern - look for it.
Or if you'd rather see a concrete example, here's how your toy example
would look
Jackson wrote:
I've got an inheritance question and was hoping brighter minds could
guide me. I am in the strange situation where some of the methods in a
subclass are actually more general than methods in a superclass. What
is the preferred way to handle such situations. My original
At Saturday 11/11/2006 03:31, Frank Millman wrote:
Continuing your analogy of animals, assume a class A with a 'walk'
method and an 'eat' method.
Most animals walk the same way, but a few don't, so I create a subclass
AW and override the walk method.
Most animals eat the same way, but a few
On Jan 16, 2005, at 9:08 AM, bwobbones wrote:
class two(one):
def __init__(self):
print two
You need to specifically call the superclass's __init__ here in order
for it to fire. Just add the line
super(two, self).__init__()
as the first line of the subclass's __init__.
bwobbones wrote:
Hi all,
I'm a java programmer struggling to come to terms with python - bear
with me!
Welcome!
I'm trying to subclass a class, and I want to be able to see it's
attributes also. Here are my classes:
[snip]
class two(one):
def __init__(self):
print two
The problem is
In article [EMAIL PROTECTED],
Ed Leafe [EMAIL PROTECTED] wrote:
On Jan 16, 2005, at 9:08 AM, bwobbones wrote:
class two(one):
def __init__(self):
print two
You need to specifically call the superclass's __init__ here in order
for it to fire. Just add the line
On Sun, 16 Jan 2005 22:08:13 +0800, bwobbones wrote:
Hi all,
I'm a java programmer struggling to come to terms with python - bear
with me!
Christophe already identified the problem, I wanted to address another
Javaism in your code, for your educational benefit.
Speaking idiomatically
63 matches
Mail list logo