On Mon, Nov 19, 2007 at 04:33:39PM +0100, Bruno Desthuilliers wrote regarding
Re: overriding methods - two questions:
>
> J. Clifford Dyer a ?crit :
> > On Mon, Nov 19, 2007 at 01:41:46PM +0100, Bruno Desthuilliers wrote
> > regarding Re: overriding methods - two questions:
&g
J. Clifford Dyer a écrit :
> On Mon, Nov 19, 2007 at 01:41:46PM +0100, Bruno Desthuilliers wrote regarding
> Re: overriding methods - two questions:
>> Steven D'Aprano a ?crit :
>>> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
>>>
>>&
On Nov 19, 7:44 am, Bruno Desthuilliers wrote:
> George Sakkis a écrit :
>
>
>
> > On Nov 16, 5:03 pm, Steven D'Aprano <[EMAIL PROTECTED]
> > cybersource.com.au> wrote:
>
> >> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
> Question 1:
> Given that the user of the API ca
On Mon, Nov 19, 2007 at 01:41:46PM +0100, Bruno Desthuilliers wrote regarding
Re: overriding methods - two questions:
>
> Steven D'Aprano a ?crit :
> > On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
> >
> >>> Question 1:
> >>>
>
George Sakkis a écrit :
> On Nov 16, 5:03 pm, Steven D'Aprano <[EMAIL PROTECTED]
> cybersource.com.au> wrote:
>
>> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
Question 1:
Given that the user of the API can choose to override foo() or not, how
can I control the sig
Steven D'Aprano a écrit :
> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
>
>>> Question 1:
>>>
>>> Given that the user of the API can choose to override foo() or not, how
>>> can I control the signature that they use?
>> While technically possible (using inspect.getargspec), tryi
On Fri, 16 Nov 2007 18:30:28 -0800, George Sakkis wrote:
> On Nov 16, 5:03 pm, Steven D'Aprano <[EMAIL PROTECTED]
> cybersource.com.au> wrote:
>
>> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
>> >> Question 1:
>>
>> >> Given that the user of the API can choose to override foo()
On Sat, 17 Nov 2007 12:19:07 +0200, Donn Ingle wrote:
>> BTW, it is a convention for method names to be lower case, and classes
>> to be Title case. Seeing something like obj.Draw, most(?) Python
>> developers will expect that the Draw attribute of obj is itself a
>> class:
> Thanks, I'm pretty da
Thanks, good tips all-round. I have it working okay at the moment with all
the suggestions. It may break in future, but that's another day :)
/d
--
http://mail.python.org/mailman/listinfo/python-list
> *not* being called by the user but *by* my API (in a timeout loop).
>
> You don't know that. How can you possibly guarantee that the user won't
> find some other use for the draw() method
Well, as per your good examples, I would answer that as the parameters
passed to draw() grow in number, so
Donn Ingle wrote:
>> I am curious as to why you want to go through such contortions. What
>> do you gain.
> for obj in list:
> if obj has a foo() method:
> a = something
> b = figureitout ( )
> object.foo ( a, b )
>
> I am accepting objects of any class on a stack. Depending on their na
On Sat, 17 Nov 2007 06:47:18 +0200, Donn Ingle wrote:
>>> While technically possible (using inspect.getargspec), trying to make
>>> your code idiot-proof is a lost fight and a pure waste of time.
>
>> Worse: it's actually counter-productive! The whole idea of being able
>> to subclass a class me
En Sat, 17 Nov 2007 01:56:22 -0300, Donn Ingle <[EMAIL PROTECTED]>
escribió:
> for obj in list:
> if 'foo' in obj.__class__.__dict__:
> etc.
>
> Although I am concerned that it's a loop ('in') and so may be slower than
> some other way to detect foo().
'in' for dictionaries is fast and runs
> This is strictly a documentation matter, in my mind. Python does not
> offer any means to enforce the calling sequence of an "override method".
Yes, I hear you.
> You might be able to wrap YOUR calling code with a try/except block
> to trap errors if the callback doesn't like the "documented AP
> I am curious as to why you want to go through such contortions. What
> do you gain.
for obj in list:
if obj has a foo() method:
a = something
b = figureitout ( )
object.foo ( a, b )
I am accepting objects of any class on a stack. Depending on their nature I
want to call certain methods
>> While technically possible (using inspect.getargspec), trying to make
>> your code idiot-proof is a lost fight and a pure waste of time.
> Worse: it's actually counter-productive!
> The whole idea of being able to subclass a class means that the user
> should be able to override foo() *includi
On Nov 16, 5:03 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
> >> Question 1:
>
> >> Given that the user of the API can choose to override foo() or not, how
> >> can I control the signature that they use?
>
> > W
On Fri, 16 Nov 2007 18:28:59 +0100, Bruno Desthuilliers wrote:
>> Question 1:
>>
>> Given that the user of the API can choose to override foo() or not, how
>> can I control the signature that they use?
>
> While technically possible (using inspect.getargspec), trying to make
> your code idiot-pr
On Nov 16, 11:35 am, Donn Ingle <[EMAIL PROTECTED]> wrote:
> >This may help (on an old Python version):
> class Sam: pass
> class Judy:
> > ...def foo(self): pass
> > ...
> children = [Sam(), Judy(), Sam()]
> for child in children: hasattr(child, "foo")
> > ...
> > False
> >
Donn Ingle a écrit :
>> for child in self.childrens:
>> if 'foo' in child.__class__.__dict__:
>> child.foo()
> Bruno, you're the man! I really must take the time to look into all those
> under-under score things!
Knowing Python's object model can help, indeed !-)
Now while this kind of stuff is
> for child in self.childrens:
> if 'foo' in child.__class__.__dict__:
> child.foo()
Bruno, you're the man! I really must take the time to look into all those
under-under score things!
Thanks.
/d
--
http://mail.python.org/mailman/listinfo/python-list
>This may help (on an old Python version):
class Sam: pass
class Judy:
> ...def foo(self): pass
> ...
children = [Sam(), Judy(), Sam()]
for child in children: hasattr(child, "foo")
> ...
> False
> True
> False
That's not what my tests are showing. While Sam has no foo, it's
Donn Ingle a écrit :
> Hi,
> Here's a framework for the questions:
>
> --- In a module, part of an API ---
> class Basis ( object ):
> def foo ( self, arg ):
> pass
>
> --- In user's own code ---
> class Child ( Basis ):
> def foo ( self, not, sure ):
> ...
>
>
> Question 1:
>
> Given th
Donn Ingle:
> Say I am in class Basis, doing a loop and I have a list of Child objects. I
> want to run the foo() method for each one that *has* a foo() method.
This may help (on an old Python version):
>>> class Sam: pass
...
>>> class Judy:
... def foo(self): pass
...
>>> children = [Sam()
> Actually, Python is complaining about your user's poor choice of
> argument names. 'not' is a reserved keyword.
My example was poor, but my actual test code did't use 'not'. Python simply
checks the use of foo() to the local sig of foo() and does not go up the
chain. This is understandable and
On Nov 16, 11:03 am, Donn Ingle <[EMAIL PROTECTED]> wrote:
> Hi,
> Here's a framework for the questions:
>
> --- In a module, part of an API ---
> class Basis ( object ):
> def foo ( self, arg ):
> pass
>
> --- In user's own code ---
> class Child ( Basis ):
> def foo ( self, not, sure ):
> .
Hi,
Here's a framework for the questions:
--- In a module, part of an API ---
class Basis ( object ):
def foo ( self, arg ):
pass
--- In user's own code ---
class Child ( Basis ):
def foo ( self, not, sure ):
...
Question 1:
Given that the user of the API can choose to override foo() or
27 matches
Mail list logo