Re: default argument in method

2010-12-31 Thread DevPlayer
I agree with you Steven that the OP should avoid __getattribute__ and the like for many a thing. I also agree with your last statement. I try to answer the OP's question without much You shouldn't do this's and don't do that's. I trust them to make thier own decisions. I'd say A much better

Re: default argument in method

2010-12-30 Thread DevPlayer
There's some_object.some_method.func_defaults and some_function.func_defaults both are a settable attribute. How to set the methods func_defaults? You'd have to have code in _getattribute__(yourmethod) if not __getattr__(yourmethod) def __getattribute__(self, attr): if attr == self.my_method:

Re: default argument in method

2010-12-30 Thread Steven D'Aprano
On Thu, 30 Dec 2010 11:26:50 -0800, DevPlayer wrote: There's some_object.some_method.func_defaults Not quite -- method objects don't expose the function attributes directly. You need some_object.some_method.im_func to get the function object, which then has a func_defaults attribute. and

Re: default argument in method

2010-12-15 Thread Hans-Peter Jansen
On Monday 13 December 2010, 18:14:27 Godson Gera wrote: On Sun, Dec 12, 2010 at 5:05 PM, ernest nfdi...@gmail.com wrote: Hi, I'd like to have a reference to an instance attribute as default argument in a method. It doesn't work because self is not defined at the time the method

Re: default argument in method

2010-12-15 Thread Steven D'Aprano
On Wed, 15 Dec 2010 21:10:05 +0100, Hans-Peter Jansen wrote: Since this is a major pitfall, it might be worth mentioning, that mutable default arguments are generally a bad idea, as the default arguments are evaluated just once, hence e.g. using an empty list might contain the items, that

Re: default argument in method

2010-12-15 Thread Hans-Peter Jansen
On Thursday 16 December 2010, 00:56:31 Steven D'Aprano wrote: On Wed, 15 Dec 2010 21:10:05 +0100, Hans-Peter Jansen wrote: Since this is a major pitfall, it might be worth mentioning, that mutable default arguments are generally a bad idea, as the default arguments are evaluated just once,

Re: default argument in method

2010-12-13 Thread Jean-Michel Pichavant
ernest wrote: Hi, I'd like to have a reference to an instance attribute as default argument in a method. It doesn't work because self is not defined at the time the method signature is evaluated. For example: class C(object): def __init__(self): self.foo = 5 def m(self, val

Re: default argument in method

2010-12-13 Thread Godson Gera
On Sun, Dec 12, 2010 at 5:05 PM, ernest nfdi...@gmail.com wrote: Hi, I'd like to have a reference to an instance attribute as default argument in a method. It doesn't work because self is not defined at the time the method signature is evaluated. For example: class C(object): def

Re: default argument in method

2010-12-13 Thread Steve Holden
On 12/13/2010 12:14 PM, Godson Gera wrote: On Sun, Dec 12, 2010 at 5:05 PM, ernest nfdi...@gmail.com mailto:nfdi...@gmail.com wrote: Hi, I'd like to have a reference to an instance attribute as default argument in a method. It doesn't work because self is not defined

default argument in method

2010-12-12 Thread ernest
Hi, I'd like to have a reference to an instance attribute as default argument in a method. It doesn't work because self is not defined at the time the method signature is evaluated. For example: class C(object): def __init__(self): self.foo = 5 def m(self, val=self.foo

Re: default argument in method

2010-12-12 Thread Chris Rebert
On Sun, Dec 12, 2010 at 3:35 AM, ernest nfdi...@gmail.com wrote: Hi, I'd like to have a reference to an instance attribute as default argument in a method. It doesn't work because self is not defined at the time the method signature is evaluated. For example: class C(object):    def