Re: Match.groupdict: Meaning of default argument?

2022-05-03 Thread Loris Bennett
Julio Di Egidio writes: > On Friday, 29 April 2022 at 09:50:08 UTC+2, Loris Bennett wrote: >> Hi, >> >> If I do >> >> import re >> pattern = >> re.compile(r'(?P\d*)(-?)(?P\d\d):(?P\d\d):(?P\d\d)') >> s = '104-02:47:06' >> match = pattern.search(s) >> match_dict = match.groupdict('0') >>

Re: Match.groupdict: Meaning of default argument?

2022-05-03 Thread Loris Bennett
"Loris Bennett" writes: > r...@zedat.fu-berlin.de (Stefan Ram) writes: > >> "Loris Bennett" writes: >>>I thought that 'days' would default to '0'. >> >> It will get the value '0' if (?P\d*) does >> /not/ participate in the match. >> >> In your case, it /does/ participate in the match, >>

Re: Match.groupdict: Meaning of default argument?

2022-05-03 Thread Loris Bennett
r...@zedat.fu-berlin.de (Stefan Ram) writes: > "Loris Bennett" writes: >>I thought that 'days' would default to '0'. > > It will get the value '0' if (?P\d*) does > /not/ participate in the match. > > In your case, it /does/ participate in the match, > \d* matching the empty string. > >

Match.groupdict: Meaning of default argument?

2022-04-29 Thread Loris Bennett
Hi, If I do import re pattern = re.compile(r'(?P\d*)(-?)(?P\d\d):(?P\d\d):(?P\d\d)') s = '104-02:47:06' match = pattern.search(s) match_dict = match.groupdict('0') I get match_dict {'days': '104', 'hours': '02', 'minutes': '47', 'seconds': '06'} However, if the string has no in

Re: default argument value is mutable

2016-10-07 Thread Marko Rauhamaa
"D'Arcy J.M. Cain" : > On Fri, 07 Oct 2016 16:09:19 +0200 > jmp wrote: >> What about >> >> def test(): >>if not hasattr(test, '_store'): test._store={'x':0} >>test._store['x'] += 1 > > Why is everyone working so hard to avoid creating a class? Hear, hear! Marko -- https://mail.python

Re: default argument value is mutable

2016-10-07 Thread ast
quot; a écrit dans le message de news:mailman.209.1475841371.30834.python-l...@python.org... On 10/07/2016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutable" Cheers, It can be used to store some variables from one call of a function t

Re: default argument value is mutable

2016-10-07 Thread D'Arcy J.M. Cain
On Fri, 07 Oct 2016 16:09:19 +0200 jmp wrote: > What about > > def test(): >if not hasattr(test, '_store'): test._store={'x':0} >test._store['x'] += 1 Why is everyone working so hard to avoid creating a class? -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:da.

Re: default argument value is mutable

2016-10-07 Thread jmp
016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutable" Cheers, It can be used to store some variables from one call of a function to an other one. def test( _store={'x':0}): x = _store['x'] . do some stu

Re: default argument value is mutable

2016-10-07 Thread ast
So the rule of thumb for default argument value is "No mutable" Cheers, It can be used to store some variables from one call of a function to an other one. def test( _store={'x':0}): x = _store['x'] . do some stuff _store['x'] = x Fo

Re: default argument value is mutable

2016-10-07 Thread Steve D'Aprano
*is* a standard idiom. > That is if you care about anyone reading your code ;) Here's another example of a mutable default argument: https://www.python.org/doc/essays/graphs/ Although it isn't actually being mutated. Nevertheless, if it is good enough for Guido, then it should be

Re: default argument value is mutable

2016-10-07 Thread Steve D'Aprano
On Fri, 7 Oct 2016 10:38 pm, Daiyue Weng wrote: > Hi, I declare two parameters for a function with default values [], > > def one_function(arg, arg1=[], arg2=[]): > > PyCharm warns me: > > Default argument value is mutable, > > what does it mean? and how to fix i

Re: default argument value is mutable

2016-10-07 Thread jmp
On 10/07/2016 02:07 PM, ast wrote: "jmp" a écrit dans le message de news:mailman.209.1475841371.30834.python-l...@python.org... On 10/07/2016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutable" Cheers, It can be used to

Re: default argument value is mutable

2016-10-07 Thread ast
"jmp" a écrit dans le message de news:mailman.209.1475841371.30834.python-l...@python.org... On 10/07/2016 01:38 PM, Daiyue Weng wrote: So the rule of thumb for default argument value is "No mutable" Cheers, It can be used to store some variables from one call

Re: default argument value is mutable

2016-10-07 Thread ast
"Daiyue Weng" a écrit dans le message de news:mailman.208.1475840291.30834.python-l...@python.org... Hi, I declare two parameters for a function with default values [], def one_function(arg, arg1=[], arg2=[]): PyCharm warns me: Default argument value is mutable, what does it mea

Re: default argument value is mutable

2016-10-07 Thread jmp
On 10/07/2016 01:38 PM, Daiyue Weng wrote: Hi, I declare two parameters for a function with default values [], def one_function(arg, arg1=[], arg2=[]): PyCharm warns me: Default argument value is mutable, what does it mean? and how to fix it? cheers You'll run into this bug def

default argument value is mutable

2016-10-07 Thread Daiyue Weng
Hi, I declare two parameters for a function with default values [], def one_function(arg, arg1=[], arg2=[]): PyCharm warns me: Default argument value is mutable, what does it mean? and how to fix it? cheers -- https://mail.python.org/mailman/listinfo/python-list

Re: How do we pass default argument value to create thread object?

2014-03-12 Thread Zachary Ware
On Wed, Mar 12, 2014 at 8:09 AM, Piyush Verma <114piy...@gmail.com> wrote: > Hi, > > I am using Thread class to create threads. > > thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"]) > thread.start() > > > This code is throwing compilation error(Ipython). > In [19]: import threa

Re: How do we pass default argument value to create thread object?

2014-03-12 Thread Jean-Michel Pichavant
- Original Message - > Hi, > I am using Thread class to create threads. > > thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"]) > thread.start() > > This code is throwing compilation error(Ipython). > In [19]: import threading > In [20]: def Fun(agr1, arg2, arg3=No

How do we pass default argument value to create thread object?

2014-03-12 Thread Piyush Verma
Hi, I am using Thread class to create threads. thread = threading.Thread(target=Fun, args=[arg1, arg2, arg3="val"]) thread.start() This code is throwing compilation error(Ipython). In [19]: import threading In [20]: def Fun(agr1, arg2, arg3=None): : pass : In [21]: thread =

Re: Modifying the default argument of function

2014-01-21 Thread Asaf Las
On Tuesday, January 21, 2014 9:46:16 PM UTC+2, Chris Angelico wrote: > On Wed, Jan 22, 2014 at 6:36 AM, Mû wrote: > > These were clear and quick answers to my problem. I did not think of this > > possibility: the default argument is created once, but accessible only by > > th

Re: Modifying the default argument of function

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 6:36 AM, Mû wrote: > These were clear and quick answers to my problem. I did not think of this > possibility: the default argument is created once, but accessible only by > the function, therefore is not a global variable, whereas it looks like if > it were at

Re: Modifying the default argument of function

2014-01-21 Thread
indeed, I thought that [2,3] was the default argument of the function f, thus I expected the three calls of f() to be exactly equivalent. In a sense, there is. The default for the argument is simply an object like any other, and it's stored in one place. For cases where you want a mutable

Re: Modifying the default argument of function

2014-01-21 Thread Chris Angelico
On Wed, Jan 22, 2014 at 6:11 AM, Mû wrote: > The function acts as if there were a global variable x, but the call of x > results in an error (undefined variable). I don't understand why the > successive calls of f() don't return the same value: indeed, I thought that >

Re: Modifying the default argument of function

2014-01-21 Thread emile
in an error (undefined variable). I don't understand why the successive calls of f() don't return the same value: indeed, I thought that [2,3] was the default argument of the function f, thus I expected the three calls of f() to be exactly equivalent. I'm don't know much about

Re: Modifying the default argument of function

2014-01-21 Thread Steve Jones
; The results are [2, 3, 1], [2, 3, 1, 1] and [2, 3, 1, 1, 1]. > > The function acts as if there were a global variable x, but the call of > x results in an error (undefined variable). I don't understand why the > successive calls of f() don't return the same value: indeed,

Modifying the default argument of function

2014-01-21 Thread
the call of x results in an error (undefined variable). I don't understand why the successive calls of f() don't return the same value: indeed, I thought that [2,3] was the default argument of the function f, thus I expected the three calls of f() to be exactly equivalent. I'm

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steven D'Aprano
On Mon, 12 Nov 2012 00:31:53 +, Oscar Benjamin wrote: [...] >>> You were right the first time, Chris. A point that happens to coincide >>> with the arbitrarily chosen origin is no more truthy or falsey than >>> any other. A vector of length 0 on the other hand is a very different >>> beast. >>

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Oscar Benjamin
On 12 November 2012 01:29, Mark Lawrence wrote: > On 12/11/2012 01:18, Oscar Benjamin wrote: >> >> On 12 November 2012 01:10, Mark Lawrence wrote: >>> >>> On 12/11/2012 00:31, Oscar Benjamin wrote: Plain wrong. Vectors are not defined *from any origin*. >>> >>> So when the Captain says

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Roy Smith
In article , Oscar Benjamin wrote: > But then I'm assuming you meant that 245 degrees was a bearing > relative to North. Was it supposed to be relative to my current angle? > Truthfully I wouldn't know what to do without asking the captain a > couple more questions. Granted, this requires some

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Mark Lawrence
On 12/11/2012 01:15, Roy Smith wrote: In article , Mark Lawrence wrote: On 12/11/2012 00:31, Oscar Benjamin wrote: Plain wrong. Vectors are not defined *from any origin*. So when the Captain says "full speed ahead, steer 245 degrees", you haven't the faintest idea where you're going, be

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Mark Lawrence
On 12/11/2012 01:18, Oscar Benjamin wrote: On 12 November 2012 01:10, Mark Lawrence wrote: On 12/11/2012 00:31, Oscar Benjamin wrote: Plain wrong. Vectors are not defined *from any origin*. So when the Captain says "full speed ahead, steer 245 degrees", you haven't the faintest idea where

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Roy Smith
In article , Mark Lawrence wrote: > On 12/11/2012 00:31, Oscar Benjamin wrote: > > > > Plain wrong. Vectors are not defined *from any origin*. > > > > So when the Captain says "full speed ahead, steer 245 degrees", you > haven't the faintest idea where you're going, because you have no origin?

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Oscar Benjamin
On 12 November 2012 01:10, Mark Lawrence wrote: > On 12/11/2012 00:31, Oscar Benjamin wrote: >> >> >> Plain wrong. Vectors are not defined *from any origin*. >> > > So when the Captain says "full speed ahead, steer 245 degrees", you haven't > the faintest idea where you're going, because you have

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Mark Lawrence
On 12/11/2012 00:31, Oscar Benjamin wrote: Plain wrong. Vectors are not defined *from any origin*. So when the Captain says "full speed ahead, steer 245 degrees", you haven't the faintest idea where you're going, because you have no origin? -- Cheers. Mark Lawrence. -- http://mail.python

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steve Howell
On Nov 11, 4:31 pm, Oscar Benjamin wrote: > On 11 November 2012 22:31, Steven D'Aprano > > Nonsense. The length and direction of a vector is relative to the origin. > > If the origin is arbitrary, as you claim, then so is the length of the > > vector. > > Wrong on all counts. Neither the length n

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steve Howell
On Nov 10, 11:33 am, Jennie wrote: > What is the best solution to solve the following problem in Python 3.3? > > import math >  >>> class Point: > ...     def __init__(self, x=0, y=0): > ...         self.x = x > ...         self.y = y > ...     def __sub__(self, other): > ...         return Point(

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Oscar Benjamin
On 11 November 2012 22:31, Steven D'Aprano wrote: > On Sun, 11 Nov 2012 14:21:19 +, Oscar Benjamin wrote: > >> On 11 November 2012 02:47, Chris Angelico wrote: >>> On Sun, Nov 11, 2012 at 1:43 PM, Ian Kelly >>> wrote: On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: > I

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Steven D'Aprano
On Sun, 11 Nov 2012 14:21:19 +, Oscar Benjamin wrote: > On 11 November 2012 02:47, Chris Angelico wrote: >> On Sun, Nov 11, 2012 at 1:43 PM, Ian Kelly >> wrote: >>> On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico >>> wrote: I would not assume that. The origin is a point, just like any

Re: Method default argument whose type is the class not yet defined

2012-11-11 Thread Oscar Benjamin
On 11 November 2012 02:47, Chris Angelico wrote: > On Sun, Nov 11, 2012 at 1:43 PM, Ian Kelly wrote: >> On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: >>> I would not assume that. The origin is a point, just like any other. >>> With a Line class, you could deem a zero-length line to be l

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Ian Kelly
On Sat, Nov 10, 2012 at 11:43 PM, Ian Kelly wrote: > Where I wrote "(0,0) is the origin" above I was not referring to a > point, not a tuple, but I can see how that was confusing. What I meant to say is I *was* referring to a point. Gah! -- http://mail.python.org/mailman/listinfo/python-list

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Ian Kelly
On Sat, Nov 10, 2012 at 7:53 PM, Roy Smith wrote: > In article , > Ian Kelly wrote: > >> On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: >> > I would not assume that. The origin is a point, just like any other. >> > With a Line class, you could deem a zero-length line to be like a >> > z

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Roy Smith
In article , Ian Kelly wrote: > On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: > > I would not assume that. The origin is a point, just like any other. > > With a Line class, you could deem a zero-length line to be like a > > zero-element list, but Point(0,0) is more like the tuple (0,0

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Chris Angelico
On Sun, Nov 11, 2012 at 1:43 PM, Ian Kelly wrote: > On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: >> I would not assume that. The origin is a point, just like any other. >> With a Line class, you could deem a zero-length line to be like a >> zero-element list, but Point(0,0) is more like

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Ian Kelly
On Sat, Nov 10, 2012 at 7:13 PM, Chris Angelico wrote: > I would not assume that. The origin is a point, just like any other. > With a Line class, you could deem a zero-length line to be like a > zero-element list, but Point(0,0) is more like the tuple (0,0) which > is definitely True. It's more

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Chris Angelico
On Sun, Nov 11, 2012 at 12:13 PM, Steven D'Aprano wrote: > Almost but not quite. I assume that, in a full Point class, you would > want Point(0, 0) to count as false in a boolean context. (A "falsey" > value, like None, [], 0.0, etc.) I would not assume that. The origin is a point, just like any

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Oscar Benjamin
On 10 November 2012 19:33, Jennie wrote: > What is the best solution to solve the following problem in Python 3.3? > > import math class Point: > ... def __init__(self, x=0, y=0): > ... self.x = x > ... self.y = y > ... def __sub__(self, other): > ... return Po

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Steven D'Aprano
On Sat, 10 Nov 2012 20:33:05 +0100, Jennie wrote: [...] > I propose three solutions. The first one: > > >>> class Point: > ... def __init__(self, x=0, y=0): > ... self.x = x > ... self.y = y > ... def __sub__(self, other): > ... return Point(self.x - other.x, self

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Dave Angel
On 11/10/2012 03:51 PM, Jennie wrote: > On 11/10/2012 09:29 PM, Terry Reedy wrote: > >> On 11/10/2012 2:33 PM, Jennie wrote: >>> >>> I propose three solutions. The first one: >>> >>> >>> class Point: >>> ... def __init__(self, x=0, y=0): >>> ... self.x = x >>> ... self.y = y >>

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Jennie
On 11/10/2012 09:29 PM, Terry Reedy wrote: On 11/10/2012 2:33 PM, Jennie wrote: I propose three solutions. The first one: >>> class Point: ... def __init__(self, x=0, y=0): ... self.x = x ... self.y = y ... def __sub__(self, other): ... return Point(self.x - o

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Terry Reedy
On 11/10/2012 2:33 PM, Jennie wrote: What is the best solution to solve the following problem in Python 3.3? import math >>> class Point: ... def __init__(self, x=0, y=0): ... self.x = x ... self.y = y ... def __sub__(self, other): ... return Point(self.x - other

Re: Method default argument whose type is the class not yet defined

2012-11-10 Thread Chris Angelico
On Sun, Nov 11, 2012 at 6:33 AM, Jennie wrote: > ... def distance(self, point=None): > ... p = point if point else Point() I'd go with this one. Definitely not the third one, which mutates the class according to a current global every time a Point is instantiated - could be *extremely

Method default argument whose type is the class not yet defined

2012-11-10 Thread Jennie
What is the best solution to solve the following problem in Python 3.3? import math >>> class Point: ... def __init__(self, x=0, y=0): ... self.x = x ... self.y = y ... def __sub__(self, other): ... return Point(self.x - other.x, self.y - other.y) ... def dista

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 solu

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-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-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

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 Monday 13 December 2010, 18:14:27 Godson Gera wrote: > On Sun, Dec 12, 2010 at 5:05 PM, 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&quo

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 <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

Re: default argument in method

2010-12-13 Thread Godson Gera
On Sun, Dec 12, 2010 at 5:05 PM, 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:

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

Re: default argument in method

2010-12-12 Thread Chris Rebert
On Sun, Dec 12, 2010 at 3:35 AM, 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:

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

Re: default argument

2010-05-11 Thread Terry Reedy
On 5/11/2010 3:41 PM, Back9 wrote: self._value will be instance variable Then set it in the __init__ method. Read the tutorial and ref manual on Python class statements, which are a bit different from what you might be used to. -- http://mail.python.org/mailman/listinfo/python-list

Re: default argument

2010-05-11 Thread Dave Angel
meant class test: self._value =0 def func(self, pos =elf._value) You're still defining the class, so how could there possibly be an instance of it to refer to as "self" yet (outside of a method body)? Also, just so you know, default argument values are only evaluated once, at t

Re: default argument

2010-05-11 Thread j vickroy
Back9 wrote: Hi, Is this grammer working in Python? class test: self._value = 10 def func(self, self._value) When i try it, it complains about undefined self. i don't know why. TIA ... not exactly; try: class Test: _value = 10 def func(self): print id(self._value), self._v

Re: default argument

2010-05-11 Thread Chris Rebert
>> i don't know why. >> >> >> TIA >> >> > Sorry >> > here is the what i meant >> > class test: >> >  self._value = 10 >> >  def func(self, pos = self._value) >> >> You're still defining the class, so h

Re: default argument

2010-05-11 Thread Back9
t; > here is the what i meant > > class test: > >  self._value = 10 > >  def func(self, pos = self._value) > > You're still defining the class, so how could there possibly be an > instance of it to refer to as "self" yet (outside of a method body)? >

Re: default argument

2010-05-11 Thread Chris Rebert
10 >  def func(self, pos = self._value) You're still defining the class, so how could there possibly be an instance of it to refer to as "self" yet (outside of a method body)? Also, just so you know, default argument values are only evaluated once, at the time the function/method is d

Re: default argument

2010-05-11 Thread Back9
On May 11, 3:06 pm, Back9 wrote: > Hi, > > Is this grammer working in Python? > > class test: >   self._value = 10 >   def func(self, self._value) > > When i try it, it complains about undefined self. > > i don't know why. > > TIA Sorry here is the what i meant class test: self._value = 10 de

default argument

2010-05-11 Thread Back9
Hi, Is this grammer working in Python? class test: self._value = 10 def func(self, self._value) When i try it, it complains about undefined self. i don't know why. TIA -- http://mail.python.org/mailman/listinfo/python-list

Re: Default Argument Question

2008-10-29 Thread Benjamin Kaplan
On Wed, Oct 29, 2008 at 12:44 PM, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Chris Rebert a écrit : > (snip) > >> Note that the "accumulation" behavior of lists is considered an >> aberration >> > > By who ? > All the python newbies who don't read the tutorial and get tripped up by this.

Re: Default Argument Question

2008-10-29 Thread Bruno Desthuilliers
Chris Rebert a écrit : (snip) Note that the "accumulation" behavior of lists is considered an aberration By who ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Default Argument Question

2008-10-29 Thread Bruno Desthuilliers
Paulo J. Matos a écrit : Hi all, Going through the tutorial brought up a question. Consider the functions: def f(a, L=[]): L.append(a) return L print f(3) print f(9) print f(7) def f1(i = 0): i = i + 1 print i f1() f1() f1() f1() Since the f accumulates the values in L, I wa

Re: Default Argument Question

2008-10-29 Thread Chris Rebert
On Wed, Oct 29, 2008 at 9:14 AM, Paulo J. Matos <[EMAIL PROTECTED]> wrote: > Hi all, > > Going through the tutorial brought up a question. Consider the functions: > > def f(a, L=[]): >L.append(a) >return L > > print f(3) > print f(9) > print f(7) > > def f1(i = 0): >i = i + 1 >print

Default Argument Question

2008-10-29 Thread Paulo J. Matos
Hi all, Going through the tutorial brought up a question. Consider the functions: def f(a, L=[]): L.append(a) return L print f(3) print f(9) print f(7) def f1(i = 0): i = i + 1 print i f1() f1() f1() f1() Since the f accumulates the values in L, I was expecting to see i printi

Re: What value should be passed to make a function use the default argument value?

2006-10-13 Thread Steve Holden
Antoon Pardon wrote: > On 2006-10-12, Magnus Lycka <[EMAIL PROTECTED]> wrote: > >>Antoon Pardon wrote: >> >>>Well maybe he didn't intend that, but how is the reader of the >>>documentation to know that? The reader can only go by how >>>things are documented. If those are not entirely consistent >>

Re: What value should be passed to make a function use the default argument value?

2006-10-13 Thread Antoon Pardon
On 2006-10-12, Magnus Lycka <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: >> Well maybe he didn't intend that, but how is the reader of the >> documentation to know that? The reader can only go by how >> things are documented. If those are not entirely consistent >> with the intend of the progr

Re: What value should be passed to make a function use the default argument value?

2006-10-12 Thread Magnus Lycka
Antoon Pardon wrote: > Well maybe he didn't intend that, but how is the reader of the > documentation to know that? The reader can only go by how > things are documented. If those are not entirely consistent > with the intend of the programmer, that is not the readers > fault. I don't think I ever

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread hanumizzle
On 6 Oct 2006 10:57:01 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: > Again that is not the fault of those that read the documentation. If > this discinction can't be easily made in python 2.X, you can't fault > the reader for coming to a conclusion that seems to follow rather > naturally from ho

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Steven D'Aprano
On Fri, 06 Oct 2006 12:42:08 +0200, Fredrik Lundh wrote: > Antoon Pardon wrote: > >> IMO this is a very natural thought process for a python programmer. >> So a python programmer seeing the first will tend to expect that >> last call to work. > > on the other hand, if a Python programmer *writes

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: > >> IMO this is a very natural thought process for a python programmer. >> So a python programmer seeing the first will tend to expect that >> last call to work. > > on the other hand, if a Python programmer *writes* so

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Fredrik Lundh
Antoon Pardon wrote: > IMO this is a very natural thought process for a python programmer. > So a python programmer seeing the first will tend to expect that > last call to work. on the other hand, if a Python programmer *writes* some code instead; say, a trivial function like: def calc

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > hanumizzle wrote: > >> Not sure exactly what is going on / being argued about in this > > thread > > I'm describing best practices based on long experience of using and > developing and teaching and writing about Python stuff. Others have

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-06, hanumizzle <[EMAIL PROTECTED]> wrote: > On 6 Oct 2006 09:21:11 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: >> On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: >> > Antoon Pardon wrote: >> > >> >> Is this general rules documeted somewhere? My impression is that readers >> >>

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Fredrik Lundh
hanumizzle wrote: > Not sure exactly what is going on / being argued about in this > thread I'm describing best practices based on long experience of using and developing and teaching and writing about Python stuff. Others have other priorities, it seems. > This doesn't say anything positiv

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread hanumizzle
On 6 Oct 2006 09:21:11 GMT, Antoon Pardon <[EMAIL PROTECTED]> wrote: > On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > Antoon Pardon wrote: > > > >> Is this general rules documeted somewhere? My impression is that readers > >> of the documentation will treat arguments as keyword argumen

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Antoon Pardon wrote: > >> Is this general rules documeted somewhere? My impression is that readers >> of the documentation will treat arguments as keyword arguments unless >> this is explicitly contradicted. > > Sorry, I missed that this was

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Fredrik Lundh
Antoon Pardon wrote: > Is this general rules documeted somewhere? My impression is that readers > of the documentation will treat arguments as keyword arguments unless > this is explicitly contradicted. Sorry, I missed that this was comp.lang.python.alternate.reality. My mistake. -- http://

Re: What value should be passed to make a function use the default argument value?

2006-10-06 Thread Antoon Pardon
On 2006-10-04, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Georg Brandl wrote: > >> This is an issue in most Python documentation: you're not told >> if the described function is implemented in C, and if it is >> keyword arg-enabled. The arguments must be given names though, >> to be able to documen

Re: What value should be passed to make a function use the default argument value?

2006-10-05 Thread Fredrik Lundh
Ben Finney wrote: > Perhaps you meant something other than "if the documentation doesn't > explicitly say that something is a keyword argument, it isn't", then. I'm sure it's perfectly possibly to use your foot as a door stop, but does that really mean that it is one? -- http://mail.python.o

Re: What value should be passed to make a function use the default argument value?

2006-10-05 Thread Ben Finney
Fredrik Lundh <[EMAIL PROTECTED]> writes: > Gabriel Genellina wrote: > > >> > the general rule is that if the documentation doesn't > >> > explicitly say that something is a keyword argument, it isn't, > >> > and shouldn't be treated as such. > > you guys need to look up the words "should" and "no

Re: What value should be passed to make a function use the default argument value?

2006-10-05 Thread Fredrik Lundh
Gabriel Genellina wrote: >> > the general rule is that if the documentation doesn't explicitly say >> > that something is a keyword argument, it isn't, and shouldn't be >> > treated as such. >> >> The first module I looked in to check this, it wasn't true. In the Queue >> Module is isn't explicit

Re: What value should be passed to make a function use the default argument value?

2006-10-05 Thread Gabriel Genellina
At Thursday 5/10/2006 11:41, Antoon Pardon wrote: > the general rule is that if the documentation doesn't explicitly say > that something is a keyword argument, it isn't, and shouldn't be treated > as such. The first module I looked in to check this, it wasn't true. In the Queue Module is isn't

Re: What value should be passed to make a function use the default argument value?

2006-10-05 Thread Steve Holden
Fredrik Lundh wrote: > Antoon Pardon wrote: > > >>The first module I looked in to check this, it wasn't true. In the Queue >>Module is isn't explicitly written that maxsize is a keyword argument yet >>Queue.Queue(maxsize=9) works just fine. > > > it's not a matter whether it works fine in any g

Re: What value should be passed to make a function use the default argument value?

2006-10-05 Thread Fredrik Lundh
Antoon Pardon wrote: > The first module I looked in to check this, it wasn't true. In the Queue > Module is isn't explicitly written that maxsize is a keyword argument yet > Queue.Queue(maxsize=9) works just fine. it's not a matter whether it works fine in any given version of Python, it's a mat

Re: What value should be passed to make a function use the default argument value?

2006-10-05 Thread Antoon Pardon
On 2006-10-04, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Georg Brandl wrote: > >> This is an issue in most Python documentation: you're not told >> if the described function is implemented in C, and if it is >> keyword arg-enabled. The arguments must be given names though, >> to be able to documen

Re: What value should be passed to make a function use the default argument value?

2006-10-04 Thread Fredrik Lundh
Georg Brandl wrote: > This is an issue in most Python documentation: you're not told > if the described function is implemented in C, and if it is > keyword arg-enabled. The arguments must be given names though, > to be able to document them. the general rule is that if the documentation doesn't

Re: What value should be passed to make a function use the default argument value?

2006-10-04 Thread Georg Brandl
Paul Rubin wrote: > Antoon Pardon <[EMAIL PROTECTED]> writes: >> repeat(object[, times]) >> Make an iterator that returns object over and over again. Runs >> indefinitely unless the times argument is specified. ... >> >> My first impression from this, is that it is possible to call >> this

Re: What value should be passed to make a function use the default argument value?

2006-10-04 Thread Antoon Pardon
On 2006-10-04, Antoon Pardon <[EMAIL PROTECTED]> wrote: > On 2006-10-03, LaundroMat <[EMAIL PROTECTED]> wrote: >> Suppose I have this function: >> >> def f(var=1): >> return var*2 >> >> What value do I have to pass to f() if I want it to evaluate var to 1? >> I know that f() will return 2, but what

  1   2   >