Re: default value in __init__

2008-10-21 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Oct 14, 1:36 pm, "David C. Ullrich" <[EMAIL PROTECTED]> wrote: > > >[...] > > > In particular default parameters should work the way the user > > expects! The fact that different users will expect different > > things

Re: default value in __init__

2008-10-20 Thread Bruno Desthuilliers
David C. Ullrich a écrit : In article <[EMAIL PROTECTED]>, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: (snip) Well... How to say.. Is there any chance these people will read anything *at all* ? No. That's exactly the point! Yeps. But I don't think we derive the same conclusions from that

Re: default value in __init__

2008-10-19 Thread Steven D'Aprano
On Sun, 19 Oct 2008 00:56:17 -0700, Paul McGuire wrote: > On Oct 14, 1:36 pm, "David C. Ullrich" <[EMAIL PROTECTED]> wrote: ... >> In particular default parameters should work the way the user expects! >> The fact that different users will expect different things here is no >> excuse... >> > Are yo

Re: default value in __init__

2008-10-19 Thread Chris Rebert
On Sun, Oct 19, 2008 at 12:56 AM, Paul McGuire <[EMAIL PROTECTED]> wrote: > On Oct 14, 1:36 pm, "David C. Ullrich" <[EMAIL PROTECTED]> wrote: >> > Well... How to say.. Is there any chance these people will read anything >> > *at all* ? >> >> No. That's exactly the point! Basic Python is so transpar

Re: default value in __init__

2008-10-19 Thread Paul McGuire
On Oct 14, 1:36 pm, "David C. Ullrich" <[EMAIL PROTECTED]> wrote: > > Well... How to say.. Is there any chance these people will read anything > > *at all* ? > > No. That's exactly the point! Basic Python is so transparent that > you can start using it without reading anything, just looking at > a

Re: default value in __init__

2008-10-19 Thread Aaron Brady
Steven D'Aprano wrote: > On Sun, 19 Oct 2008 02:52:52 +, Aaron Brady wrote: > >> Steven D'Aprano wrote: >> >>> On Sat, 18 Oct 2008 09:17:28 +1300, Lawrence D'Oliveiro wrote: >>> In message <[EMAIL PROTECTED]>, Aaron "Castironpi" Brady wrote: > The purpose of a paramet

Re: default value in __init__

2008-10-18 Thread Steven D'Aprano
On Sun, 19 Oct 2008 02:52:52 +, Aaron Brady wrote: > Steven D'Aprano wrote: > >> On Sat, 18 Oct 2008 09:17:28 +1300, Lawrence D'Oliveiro wrote: >> >>> In message >>> <[EMAIL PROTECTED]>, >>> Aaron "Castironpi" Brady wrote: >>> The purpose of a parameter is something that the caller can

Re: default value in __init__

2008-10-18 Thread Aaron Brady
Steven D'Aprano wrote: > On Sat, 18 Oct 2008 09:17:28 +1300, Lawrence D'Oliveiro wrote: > >> In message >> <[EMAIL PROTECTED]>, >> Aaron "Castironpi" Brady wrote: >> >>> The purpose of a parameter is something that the caller can supply, but >>> doesn't have to. It is not for internal-use-only i

Re: default value in __init__

2008-10-18 Thread Steven D'Aprano
On Sat, 18 Oct 2008 09:17:28 +1300, Lawrence D'Oliveiro wrote: > In message > <[EMAIL PROTECTED]>, > Aaron "Castironpi" Brady wrote: > >> The purpose of a parameter is something that the caller can supply, but >> doesn't have to. It is not for internal-use-only items. > > Exactly! Says who? U

Re: default value in __init__

2008-10-17 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote: > On Fri, 17 Oct 2008 23:04:52 +1300, Lawrence D'Oliveiro wrote: > >> The right solution, of course, is >> >> fns = [(lambda x : lambda : x)(x) for x in range(10)] > > Only if by "right solution" you mean "excessively verbose, confusing

Re: default value in __init__

2008-10-17 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Aaron "Castironpi" Brady wrote: > The purpose of a parameter is something that the caller can supply, but > doesn't have to. It is not for internal-use-only items. Exactly! -- http://mail.python.org/mailman/listinfo/python-list

Re: default value in __init__

2008-10-17 Thread Aaron "Castironpi" Brady
On Oct 17, 6:56 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 17 Oct 2008 23:04:52 +1300, Lawrence D'Oliveiro wrote: > > In message <[EMAIL PROTECTED]>, Duncan Booth wrote: > > >> We already get people asking why code like this doesn't return 3: > > > fns = [ lambd

Re: default value in __init__

2008-10-17 Thread Steven D'Aprano
On Fri, 17 Oct 2008 23:04:52 +1300, Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, Duncan Booth wrote: > >> We already get people asking why code like this doesn't return 3: >> > fns = [ lambda: x for x in range(10) ] fns[3]() >> 9 >> >> ... making this change to default argum

Re: default value in __init__

2008-10-17 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Duncan Booth wrote: > We already get people asking why code like this doesn't return 3: > fns = [ lambda: x for x in range(10) ] fns[3]() > 9 > > ... making this change to default arguments would mean the > solution usually proposed to the function scopi

Re: default value in __init__

2008-10-16 Thread Aaron "Castironpi" Brady
On Oct 16, 7:54 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Thu, 16 Oct 2008 12:18:49 -0700, Aaron \"Castironpi\" Brady wrote: > > [snip] > > >> If Python re-evaluated the default value i=i at runtime, the above > >> would break. > > > Not with a mere extra lambda. > > No

Re: default value in __init__

2008-10-16 Thread Steven D'Aprano
On Thu, 16 Oct 2008 12:18:49 -0700, Aaron \"Castironpi\" Brady wrote: [snip] >> If Python re-evaluated the default value i=i at runtime, the above >> would break. > > Not with a mere extra lambda. Not so. It has nothing to do with lambda, lambda just happens to be a convenient example. Here's

Re: default value in __init__

2008-10-16 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > David C. Ullrich a écrit : > > In article <[EMAIL PROTECTED]>, > > Bruno Desthuilliers <[EMAIL PROTECTED]> > > wrote: > > > >> David C. Ullrich a écrit : > (snip) > >>> Seems to me that people often site the "imp

Re: default value in __init__

2008-10-16 Thread Aaron "Castironpi" Brady
On Oct 16, 12:23 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Thu, 16 Oct 2008 17:05:40 +1300, Lawrence D'Oliveiro wrote: > > In message <[EMAIL PROTECTED]>, Steven D'Aprano > > wrote: > > >> On Thu, 09 Oct 2008 01:39:30 -0700, kenneth (a.k.a. Paolo) wrote: > > >>> On Oct

Re: default value in __init__

2008-10-16 Thread Aaron "Castironpi" Brady
On Oct 16, 1:05 am, "Chris Rebert" <[EMAIL PROTECTED]> wrote: > On Wed, Oct 15, 2008 at 9:43 PM, Aaron Castironpi Brady > > > > <[EMAIL PROTECTED]> wrote: > > On Oct 15, 11:33 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > >> Aaron "Castironpi" Brady wrote: > > >> [about how default argument behavio

Re: default value in __init__

2008-10-16 Thread Steven D'Aprano
On Thu, 16 Oct 2008 17:05:40 +1300, Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, Steven D'Aprano > wrote: > >> On Thu, 09 Oct 2008 01:39:30 -0700, kenneth (a.k.a. Paolo) wrote: >> >>> On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: >>> No, it always contains

Re: default value in __init__

2008-10-16 Thread bearophileHUGS
Chris Rebert: > Although primitive and likely somewhat flawed, you may find the > statistics in the "Compatibility Issues" section > ofhttp://mail.python.org/pipermail/python-3000/2007-February/005704.html > to be of interest. I am quite glad to see that I am not the only one that cares for such

Re: default value in __init__

2008-10-15 Thread Chris Rebert
On Wed, Oct 15, 2008 at 9:43 PM, Aaron Castironpi Brady <[EMAIL PROTECTED]> wrote: > On Oct 15, 11:33 pm, Steve Holden <[EMAIL PROTECTED]> wrote: >> Aaron "Castironpi" Brady wrote: >> >> [about how default argument behavior should, in his opinion, be changed] >> >> Say what you like. The language i

Re: default value in __init__

2008-10-15 Thread Aaron "Castironpi" Brady
On Oct 15, 11:33 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Aaron "Castironpi" Brady wrote: > > [about how default argument behavior should, in his opinion, be changed] > > Say what you like. The language is as it is by choice. Were it, for some > reason, to change we would then be receiving pos

Re: default value in __init__

2008-10-15 Thread Steve Holden
Aaron "Castironpi" Brady wrote: [about how default argument behavior should, in his opinion, be changed] Say what you like. The language is as it is by choice. Were it, for some reason, to change we would then be receiving posts every week that didn't understand the *new* behavior. Sometimes peop

Re: default value in __init__

2008-10-15 Thread Aaron "Castironpi" Brady
On Oct 15, 11:05 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED] central.gen.new_zealand> wrote: > In message <[EMAIL PROTECTED]>, Steven D'Aprano > wrote: > > > On Thu, 09 Oct 2008 01:39:30 -0700, kenneth (a.k.a. Paolo) wrote: > > >> On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: > > >

Re: default value in __init__

2008-10-15 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Steven D'Aprano wrote: > On Thu, 09 Oct 2008 01:39:30 -0700, kenneth (a.k.a. Paolo) wrote: > >> On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: >> >>> No, it always contains the default argument because default values are >>> created just ONE TIME <

Re: default value in __init__

2008-10-14 Thread Daniel da Silva
I would just like to add to the discussion that 4as a second year computer science undergraduate and I noticed the same "issue" with default arguments, but I was able to figure out the system of how (and why) python does it the way it does, without having to consult any documentation offline or onl

Re: default value in __init__

2008-10-14 Thread Aaron "Castironpi" Brady
On Oct 14, 1:50 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > David C. Ullrich a écrit : > > > > > In article <[EMAIL PROTECTED]>, > >  Bruno Desthuilliers <[EMAIL PROTECTED]> > >  wrote: snip > (snip) snip > > In particular default parameters should work the way the user > > expects! The fa

Re: default value in __init__

2008-10-14 Thread Bruno Desthuilliers
David C. Ullrich a écrit : In article <[EMAIL PROTECTED]>, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: David C. Ullrich a écrit : (snip) Seems to me that people often site the "important warning" in the tutorial. Of course there's no reason anyone would bother going through the tutoria

Re: default value in __init__

2008-10-14 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > David C. Ullrich a écrit : > > In article > > <[EMAIL PROTECTED]>, > > kenneth <[EMAIL PROTECTED]> wrote: > > > >> On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: > >>> kenneth wrote: > the

Re: default value in __init__

2008-10-11 Thread Aaron "Castironpi" Brady
On Oct 11, 4:41 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Fri, 10 Oct 2008 06:20:35 -0700, bearophileHUGS wrote: snip > > I have seen professional programmers too use class attributes instead of > > instance ones... > > That's only a mistake if you don't mean to use cla

Re: default value in __init__

2008-10-11 Thread Aaron "Castironpi" Brady
On Oct 10, 12:30 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > >> I don't think simply re-executing the default argument > >> expression on each call works either: that would confuse at least as > >> many people as the current system. > > > May I ask you why? I think I do

Re: default value in __init__

2008-10-11 Thread Steven D'Aprano
On Fri, 10 Oct 2008 06:20:35 -0700, bearophileHUGS wrote: >> I don't think simply re-executing the default argument expression on >> each call works either: that would confuse at least as many people as >> the current system. > > May I ask you why? I think I don't agree, but I am not sure. x = 1

Re: default value in __init__

2008-10-11 Thread Steven D'Aprano
On Thu, 09 Oct 2008 01:39:30 -0700, kenneth (a.k.a. Paolo) wrote: > On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: >> kenneth wrote: >> > the 'd' variable already contains the 'self.d' value of the first >> > instance and not the default argument {}. >> >> > Am I doing some stupid

Re: default value in __init__

2008-10-10 Thread bearophileHUGS
Chris Rebert: > The general idea been discussed ad-nauseum on the list several times > before, including just 2 months ago. See e.g.: Okay, it can't be fixed then. Bye and thank you, bearophile -- http://mail.python.org/mailman/listinfo/python-list

Re: default value in __init__

2008-10-10 Thread Duncan Booth
[EMAIL PROTECTED] wrote: >> I don't think simply re-executing the default argument >> expression on each call works either: that would confuse at least as >> many people as the current system. > > May I ask you why? I think I don't agree, but I am not sure. > My thought (which may well be wrong)

Re: default value in __init__

2008-10-10 Thread Chris Rebert
On Fri, Oct 10, 2008 at 4:36 AM, <[EMAIL PROTECTED]> wrote: > Bruno Desthuilliers: >> You mean : "to people that don't bother reading the FineManual *nor* >> searching the newsgroup / ML archives ?" > > Are there ways to change how Python3 manages arguments and functions, > to remove this antifeat

Re: default value in __init__

2008-10-10 Thread bearophileHUGS
Duncan Booth: > You can't just copy the default values on every call: you would still get > people confused by the semantics whether you did a shallow or deep copy or > as now no copy. I think I agree. > I don't think simply re-executing the default argument > expression on each call works eithe

Re: default value in __init__

2008-10-10 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > Bruno Desthuilliers: >> You mean : "to people that don't bother reading the FineManual *nor* >> searching the newsgroup / ML archives ?" > > Are there ways to change how Python3 manages arguments and functions, > to remove this antifeature of Python, avoiding this commo

Re: default value in __init__

2008-10-10 Thread bearophileHUGS
Bruno Desthuilliers: > You mean : "to people that don't bother reading the FineManual *nor* > searching the newsgroup / ML archives ?" Are there ways to change how Python3 manages arguments and functions, to remove this antifeature of Python, avoiding this common mistake done by every newbie? I do

Re: default value in __init__

2008-10-10 Thread Bruno Desthuilliers
David C. Ullrich a écrit : In article <[EMAIL PROTECTED]>, kenneth <[EMAIL PROTECTED]> wrote: On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: kenneth wrote: the 'd' variable already contains the 'self.d' value of the first instance and not the default argument {}. Am I doing

Re: default value in __init__

2008-10-09 Thread David C. Ullrich
In article <[EMAIL PROTECTED]>, kenneth <[EMAIL PROTECTED]> wrote: > On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: > > kenneth wrote: > > > the 'd' variable already contains the 'self.d' value of the first > > > instance and not the default argument {}. > > > > > Am I doing som

Re: default value in __init__

2008-10-09 Thread Bruno Desthuilliers
kenneth a écrit : On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: kenneth wrote: the 'd' variable already contains the 'self.d' value of the first instance and not the default argument {}. Am I doing some stupid error, or this is a problem ? No, it always contains the default a

Re: default value in __init__

2008-10-09 Thread Chris Rebert
On Thu, Oct 9, 2008 at 1:39 AM, kenneth <[EMAIL PROTECTED]> wrote: > On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: >> kenneth wrote: >> > the 'd' variable already contains the 'self.d' value of the first >> > instance and not the default argument {}. >> >> > Am I doing some stupid

Re: default value in __init__

2008-10-09 Thread kenneth
On Oct 9, 10:14 am, Christian Heimes <[EMAIL PROTECTED]> wrote: > kenneth wrote: > > the 'd' variable already contains the 'self.d' value of the first > > instance and not the default argument {}. > > > Am I doing some stupid error, or this is a problem ? > > No, it always contains the default argu

Re: default value in __init__

2008-10-09 Thread Christian Heimes
kenneth wrote: the 'd' variable already contains the 'self.d' value of the first instance and not the default argument {}. Am I doing some stupid error, or this is a problem ? No, it always contains the default argument because default values are created just ONE TIME. http://effbot.org/pyfa

Re: default value in __init__

2008-10-09 Thread Chris Rebert
See Pitfall #5 on http://zephyrfalcon.org/labs/python_pitfalls.html It also applies to dictionaries (and sets, any mutable object really). On Thu, Oct 9, 2008 at 1:03 AM, kenneth <[EMAIL PROTECTED]> wrote: > Dear all, > > I have encountered this weird problem. > > I have a class definition with an

default value in __init__

2008-10-09 Thread kenneth
Dear all, I have encountered this weird problem. I have a class definition with an __init__ argument 'd' which defaults to {}. This argument is put in the 'self.d' attribute at initialization I create two independent instances of this class; the code is as follows. class C: def __init__(self,