[Tutor] functions and default argument

2011-10-21 Thread Praveen Singh
In function- Default value is *evaluated only once*.This makes different when the default is a mutable object such as a list, dictionary or instance of most classes. I am not getting it properly-evaluated once?? different behaviour???-- please explain this.

Re: [Tutor] functions and default argument

2011-10-21 Thread Christian Witts
On 2011/10/21 03:00 PM, Praveen Singh wrote: In function- Default value is *evaluated only once*.This makes different when the default is a mutable object such as a list, dictionary or instance of most classes. I am not getting it properly-evaluated once?? different behaviour???-- please

Re: [Tutor] functions and default argument

2011-10-21 Thread Steven D'Aprano
Praveen Singh wrote: In function- Default value is *evaluated only once*.This makes different when the default is a mutable object such as a list, dictionary or instance of most classes. I am not getting it properly-evaluated once?? different behaviour???-- please explain this. Look at an

Re: [Tutor] functions and default argument

2011-10-21 Thread Prasad, Ramit
The same thing occurs when you use a mutable object like a list or a dict. The default value is assigned once, and once only. But notice that you can modify the default value, say by appending to it: Not sure this will work exactly the same way in other IDEs, but in mine: a = [] def

Re: [Tutor] functions and default argument

2011-10-21 Thread Albert-Jan Roskam
? ~~ From: Prasad, Ramit ramit.pra...@jpmorgan.com To: tutor@python.org tutor@python.org Sent: Friday, October 21, 2011 9:40 PM Subject: Re: [Tutor] functions and default argument The same thing occurs when you use a mutable object like a list or a dict. The default value is assigned once

Re: [Tutor] functions and default argument

2011-10-21 Thread Prasad, Ramit
Interesting thread and webpages. Insightful, but is this really used as a technique in daily practice? It feels a bit like a hack to me. Like the author of one of the websites said: rule #1 don't mess with this. I think the problem with rule #1 is that this can occur when you do *not*

Re: [Tutor] functions and default argument

2011-10-21 Thread Alan Gauld
On 21/10/11 21:40, Albert-Jan Roskam wrote: Interesting thread and webpages. Insightful, but is this really used as a technique in daily practice? Yes, one example is where you use it for a counter to determine how often a function gets called: def reserveScarceResource(p1,p2,count = [0]):

Re: [Tutor] functions and default argument

2011-10-21 Thread Steven D'Aprano
Prasad, Ramit wrote: Interesting thread and webpages. Insightful, but is this really used as a technique in daily practice? It feels a bit like a hack to me. Like the author of one of the websites said: rule #1 don't mess with this. I think the problem with rule #1 is that this can occur when