On Dec 30 2007, 12:27 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> In the absence of a better solution, I'm very comfortable with keeping
> the behaviour as is. Unfortunately, there's no good solution in Python to
> providing functions with local storage that persists across
On Jan 1, 6:48 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> En Tue, 01 Jan 2008 15:45:00 -0200, bukzor <[EMAIL PROTECTED]>
> escribi�:
[...]
> >> I'm confused by what you mean by 'early binding'. Can you give a quick-
> >> n-dirty example?
> > Is an 'early bound' variable synonymous with
En Tue, 01 Jan 2008 15:45:00 -0200, bukzor <[EMAIL PROTECTED]>
escribi�:
> On Jan 1, 9:00 am, bukzor <[EMAIL PROTECTED]> wrote:
>> On Dec 31 2007, 1:30 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
>>
>> > And also removing the only way you can currently do early binding in
>> > Python. I agree t
On Jan 1, 9:00 am, bukzor <[EMAIL PROTECTED]> wrote:
> On Dec 31 2007, 1:30 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Dec 31, 2007 2:08 PM, Odalrick <[EMAIL PROTECTED]> wrote:
>
> > > On 31 Dec, 18:22, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> > > > On Dec 31, 10:58 am, Odalric
On Jan 1, 2008 12:26 AM, NickC <[EMAIL PROTECTED]> wrote:
> On Jan 1, 3:22 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> > On Dec 31, 10:58 am, Odalrick <[EMAIL PROTECTED]> wrote:
> >
> > > I'm surprised noone has said anything about the why of default
> > > mutables. I think it is becasue it
On Dec 31 2007, 1:30 pm, "Chris Mellon" <[EMAIL PROTECTED]> wrote:
> On Dec 31, 2007 2:08 PM, Odalrick <[EMAIL PROTECTED]> wrote:
>
>
>
> > On 31 Dec, 18:22, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> > > On Dec 31, 10:58 am, Odalrick <[EMAIL PROTECTED]> wrote:
>
> > > > On 30 Dec, 17:26, George
On Dec 30 2007, 11:01 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sun, 30 Dec 2007 20:00:14 -0800, bukzor wrote:
> > I think you struck at the heart of the matter earlier when you noted
> > that this is the simplest way to declare a static variable in python.
> > Using th
On Jan 1, 5:26 am, NickC <[EMAIL PROTECTED]> wrote:
> On Jan 1, 3:22 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
>
> > On Dec 31, 10:58 am, Odalrick <[EMAIL PROTECTED]> wrote:
>
> > > I'm surprised noone has said anything about the why of default
> > > mutables. I think it is becasue it isn't e
On Jan 1, 3:22 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> On Dec 31, 10:58 am, Odalrick <[EMAIL PROTECTED]> wrote:
>
> > I'm surprised noone has said anything about the why of default
> > mutables. I think it is becasue it isn't easy to do it an other way.
>
> [...]
>
> There is an easy enou
On Dec 31, 2007 2:08 PM, Odalrick <[EMAIL PROTECTED]> wrote:
> On 31 Dec, 18:22, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> > On Dec 31, 10:58 am, Odalrick <[EMAIL PROTECTED]> wrote:
> >
> > > On 30 Dec, 17:26, George Sakkis <[EMAIL PROTECTED]> wrote:
> >
> > > > On Dec 29, 9:14 pm, bukzor <[EMA
On 31 Dec, 18:22, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> On Dec 31, 10:58 am, Odalrick <[EMAIL PROTECTED]> wrote:
>
> > On 30 Dec, 17:26, George Sakkis <[EMAIL PROTECTED]> wrote:
>
> > > On Dec 29, 9:14 pm, bukzor <[EMAIL PROTECTED]> wrote:
>
> > > > Here's the answer to the
> > > > questio
On Dec 31, 10:58 am, Odalrick <[EMAIL PROTECTED]> wrote:
> On 30 Dec, 17:26, George Sakkis <[EMAIL PROTECTED]> wrote:
>
> > On Dec 29, 9:14 pm, bukzor <[EMAIL PROTECTED]> wrote:
>
> > > Here's the answer to the
> > > question:http://www.python.org/doc/faq/general/#why-are-default-values-shared-...
On 30 Dec, 17:26, George Sakkis <[EMAIL PROTECTED]> wrote:
> On Dec 29, 9:14 pm, bukzor <[EMAIL PROTECTED]> wrote:
>
> > Here's the answer to the
> > question:http://www.python.org/doc/faq/general/#why-are-default-values-shared-...
>
> > It looks like Guido disagrees with me, so the discussion is
En Mon, 31 Dec 2007 05:01:51 -0200, Steven D'Aprano
<[EMAIL PROTECTED]> escribió:
> On Sun, 30 Dec 2007 20:00:14 -0800, bukzor wrote:
>
>> I also see this as the main use of the
>> 'notlocal' keyword to be introduced in py3k (it also fixes the example
>> given by Istvan above).
>
> There doesn't
On Sun, 30 Dec 2007 20:00:14 -0800, bukzor wrote:
> I think you struck at the heart of the matter earlier when you noted
> that this is the simplest way to declare a static variable in python.
> Using the 'global' keyword is the other way, and is much more explicit,
> and much more widely used. I
On Dec 30, 3:34 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Sun, 30 Dec 2007 12:41:57 -0800, bukzor wrote:
> > BTW, it's silly not to 'allow' globals when they're called for,
> > otherwise we wouldn't need the 'global' keyword.
>
> Nobody argues against allowing globals v
On Sun, 30 Dec 2007 13:34:07 -0800, Dennis Lee Bieber wrote:
> On Sun, 30 Dec 2007 12:11:50 -0800 (PST), bukzor
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>
>> Just because it's well known doesn't mean we shouldn't think about it.
>> For example, in the same list you li
On Sun, 30 Dec 2007 12:41:57 -0800, bukzor wrote:
> BTW, it's silly not to 'allow' globals when they're called for,
> otherwise we wouldn't need the 'global' keyword.
Nobody argues against allowing globals variables *when they're called
for*, just pointing out that ninety-nine times out of a hun
On Dec 30, 3:41 pm, bukzor <[EMAIL PROTECTED]> wrote:
> No globals, as you specified. BTW, it's silly not to 'allow' globals
> when they're called for, otherwise we wouldn't need the 'global'
> keyword.
okay, now note that you do not actually use the ingroup list for
anything else but getting and
On Dec 30, 12:32 pm, Istvan Albert <[EMAIL PROTECTED]> wrote:
> On Dec 30, 11:26 am, George Sakkis <[EMAIL PROTECTED]> wrote:
>
> > I'm with you on this one; IMHO it's one of the relatively few language
> > design missteps of Python, favoring the rare case as the default
> > instead of the common o
On Dec 30, 11:26 am, George Sakkis <[EMAIL PROTECTED]> wrote:
> I'm with you on this one; IMHO it's one of the relatively few language
> design missteps of Python, favoring the rare case as the default
> instead of the common one.
George, you pointed this out this link in a different thread
http
On Dec 30, 2:23 am, thebjorn <[EMAIL PROTECTED]>
wrote:
> Scenario: long running server process,
> Bug report: "people aren't getting older", Code:
>
>def age(dob, today=datetime.date.today()):
>...
A very interesting example, thanks.
On Dec 30, 8:25 am, [EMAIL PROTECTED] wrote:
> Thi
On Dec 30, 2:45 pm, Istvan Albert <[EMAIL PROTECTED]> wrote:
> On Dec 30, 5:23 am, thebjorn <[EMAIL PROTECTED]>
> wrote:
>
> >def age(dob, today=datetime.date.today()):
> >...
>
> > None of my unit tests caught that one :-)
>
> interesting example I can see how it caused some trouble. A
On Dec 29, 9:14 pm, bukzor <[EMAIL PROTECTED]> wrote:
> Here's the answer to the
> question:http://www.python.org/doc/faq/general/#why-are-default-values-shared-...
>
> It looks like Guido disagrees with me, so the discussion is closed.
Note that the FAQ mainly explains *what* happens, not *why*
This is a well-known python gotcha. See:
http://www.ferg.org/projects/python_gotchas.html#contents_item_6
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 29, 11:21 pm, bukzor <[EMAIL PROTECTED]> wrote:
> The standard library is not affected because
the people who wrote code into it know how python works.
Programming abounds with cases that some people think should work
differently:
a = b = []
a.append(1)
is b empty or not at this point?
On Dec 30, 5:23 am, thebjorn <[EMAIL PROTECTED]>
wrote:
>def age(dob, today=datetime.date.today()):
>...
>
> None of my unit tests caught that one :-)
interesting example I can see how it caused some trouble. A quick fix
would be to write it:
def age(dob, today=datetime.date.today ):
On Dec 29, 7:17 pm, Istvan Albert <[EMAIL PROTECTED]> wrote:
> On Dec 29, 12:50 pm, bukzor <[EMAIL PROTECTED]> wrote:
>
> > Is this functionality intended? It seems very unintuitive. This has
> > caused a bug in my programs twice so far, and both times I was
> > completely mystified until I realize
On Dec 30, 3:21 pm, bukzor <[EMAIL PROTECTED]> wrote:
> Just for completeness, the mutable default value problem also affects
> classes:
Simply, because methods are functions, and can have default arguments.
You don't need to nail *another* zillion theses to the cathedral
door :-)
--
http://mail.
Just for completeness, the mutable default value problem also affects
classes:
class c:
def __init__(self, list = []):
self.list = list
self.list.append("LIST END")
def __repr__(self):
return "" % self.list
>>> import example2
>>> print example2.c()
>>> print exam
> I think that this behaviour is a little unintuitive, and by a little I
> mean a lot.
Thanks for acknowledging it.
> I question that it is "much more common". How do you know? Where's your
> data?
I did a dumb grep of my Python25/Lib folder and found 33 occurances of
the first pattern above. (U
On Sat, 29 Dec 2007 09:50:53 -0800, bukzor wrote:
> I've found some bizzare behavior when using mutable values (lists,
> dicts, etc) as the default argument of a function.
This FAQ is so Frequently Asked that I sometimes wonder if Python should,
by default, print a warning when it compiles a fun
On Sat, 29 Dec 2007 11:14:30 -0800, bukzor wrote:
> In python25 (this function from the FAQ linked above):
> def f(a, _cache={}):
> # Callers will never provide a third parameter for this function.
> (then why is it an argument?)
The caller might want to provide it's own pre-prepared cache.
Here's the answer to the question:
http://www.python.org/doc/faq/general/#why-are-default-values-shared-between-objects
It looks like Guido disagrees with me, so the discussion is closed.
For the record, I still think the following would be an improvement to
py3k:
In python25:
def f(a=None):
On Dec 29, 1:11 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> Google for "Python mutable default arguments"
and a mere 30 minutes later this thread is already one of the results
that come up
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 29, 12:50 pm, bukzor <[EMAIL PROTECTED]> wrote:
> Is this functionality intended? It seems very unintuitive. This has
> caused a bug in my programs twice so far, and both times I was
> completely mystified until I!realized that the default value was
> changing.
it is only unintuitive when
> Is this functionality intended?
Google for "Python mutable default arguments" (you can actually
leave out Python).
It's part of the language semantics, yes.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list
I've found some bizzare behavior when using mutable values (lists,
dicts, etc) as the default argument of a function. I want to get the
community's feedback on this. It's easiest to explain with code.
This example is trivial and has design issues, but it demonstrates a
problem I've seen in product
38 matches
Mail list logo