Bruno Desthuilliers wrote:
> [EMAIL PROTECTED] wrote:
> > Bruno Desthuilliers wrote:
> >
> >>[EMAIL PROTECTED] wrote:
> (snip)
>
> >>>and 2) what's the reason to use newstyle classes
> >>>versus the old?
> >>
> >>All this is explained on python.org (there's a menu entry for this in
> >>the documen
[EMAIL PROTECTED] wrote:
> Bruno Desthuilliers wrote:
>
>>[EMAIL PROTECTED] wrote:
(snip)
>>>and 2) what's the reason to use newstyle classes
>>>versus the old?
>>
>>All this is explained on python.org (there's a menu entry for this in
>>the documentation menu). AFAICT, newstyle classes can do wh
Bruno Desthuilliers wrote:
> [EMAIL PROTECTED] wrote:
> (snip)
>
> > Two additional questions though: 1) is there a way for a function to
> > get a reference to its caller automatically (as in, without the caller
> > having to pass it in)?
>
> It's possible with sys._getframe() and a decorator - b
I can't give much answers, I am not that expert yet.
Bruno Desthuilliers:
> newstyle classes can do whatever oldstyle classes
> did, *and much more* (descriptors and usable
> metaclasses) - and they are somewhat faster too.
In the past I have done few tests, and it seemed that new style classes
a
[EMAIL PROTECTED] wrote:
(snip)
> Two additional questions though: 1) is there a way for a function to
> get a reference to its caller automatically (as in, without the caller
> having to pass it in)?
It's possible with sys._getframe() and a decorator - but consider it a
hack.
> and 2) what's th
Okay, while I'd still like to know the answer(s) to my earlier
question(s), I've mostly solved my problem thanks to bearophile and my
own learning. An example:
class Cat(object):
def __init__(self):
self.love = 0
def meow(self):
print "meow"
class Dog(object):
def bark(
This looks excellent bearophile, but I'm having trouble understanding
some things. Perhaps you can help wipe clean my ignorance. Firstly, I
thought __classes__ was a read-only attribute? Secondly, what is a
"dictproxy object" and why won't the following code work:
class Cat:
def meow(self):
I think it's possible, most of such kind of things are possible with
Python.
I'm not an expert yet in such kind of things, so this can be a starting
point for you (note the shadowing of m2, the class docstrings, etc).
Other people can give you something better or more correct.
class A:
def m1(
Hi all. If I have an instance of class A, called say foo, and I need to
mix-in the functions and variables of another class (class B) to this
instance at runtime, how do I do it? In other words, I want to make foo
an instance of an anonymous and temporary class that inherits its
functionality from