Re: use str as variable name

2008-09-06 Thread Fredrik Lundh
Marco Bizzarri wrote: Just a question: "generic functions" are not meant in the sense of "generic functions" of CLOS, am I right? >> it's meant in exactly that sense: len(L) means "of all len() implementations available to the runtime, execute the most specific code we have for the object L".

Re: use str as variable name

2008-09-05 Thread Michele Simionato
On Sep 6, 8:02 am, "Marco Bizzarri" <[EMAIL PROTECTED]> wrote: > On Fri, Sep 5, 2008 at 9:16 PM, Bruno Desthuilliers > > <[EMAIL PROTECTED]> wrote: > > Marco Bizzarri a écrit : > > >> Just a question: "generic functions" are not meant in the sense of > >> "generic functions" of CLOS, am I right? >

Re: use str as variable name

2008-09-05 Thread Marco Bizzarri
On Sat, Sep 6, 2008 at 7:52 AM, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Marco Bizzarri wrote: > >>> (...as Bruno implies, setattr(), len() et al can be and should be viewed >>> as >>> generic functions. >> >> Just a question: "generic functions" are not meant in the sense of >> "generic function

Re: use str as variable name

2008-09-05 Thread Marco Bizzarri
On Fri, Sep 5, 2008 at 9:16 PM, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Marco Bizzarri a écrit : >> >> Just a question: "generic functions" are not meant in the sense of >> "generic functions" of CLOS, am I right? > > Nope. Just "generic" in the sense that they accept any object implementi

Re: use str as variable name

2008-09-05 Thread Fredrik Lundh
Marco Bizzarri wrote: (...as Bruno implies, setattr(), len() et al can be and should be viewed as generic functions. Just a question: "generic functions" are not meant in the sense of "generic functions" of CLOS, am I right? it's meant in exactly that sense: len(L) means "of all len() imple

Re: use str as variable name

2008-09-05 Thread Bruno Desthuilliers
Marco Bizzarri a écrit : On Thu, Sep 4, 2008 at 10:47 AM, Fredrik Lundh <[EMAIL PROTECTED]> wrote: (...as Bruno implies, setattr(), len() et al can be and should be viewed as generic functions. Just a question: "generic functions" are not meant in the sense of "generic functions" of CLOS, am

Re: use str as variable name

2008-09-05 Thread Marco Bizzarri
On Thu, Sep 4, 2008 at 10:47 AM, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > > (...as Bruno implies, setattr(), len() et al can be and should be viewed as > generic functions. Just a question: "generic functions" are not meant in the sense of "generic functions" of CLOS, am I right? -- Marco Biz

Re: use str as variable name

2008-09-04 Thread Mathieu Prevot
2008/9/4 Fredrik Lundh <[EMAIL PROTECTED]>: > Bruno Desthuilliers wrote: > >> You wouldn't write something like 2.__add__(3), would you ? > > Don't give the "it's only OO if I write obj.method(args)" crowd more bad > ideas, please ;-) > > (...as Bruno implies, setattr(), len() et al can be and shou

Re: use str as variable name

2008-09-04 Thread Cameron Laird
In article <[EMAIL PROTECTED]>, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Mathieu Prevot a écrit : >> 2008/9/4 Chris Rebert <[EMAIL PROTECTED]>: > >(snip) > >>> You're looking for the setattr() built-in function. In this exact case: >>>setattr(a, arg, new_value) >>> >>> This is probably

Re: use str as variable name

2008-09-04 Thread Fredrik Lundh
Bruno Desthuilliers wrote: > You wouldn't write something like 2.__add__(3), would you ? Don't give the "it's only OO if I write obj.method(args)" crowd more bad ideas, please ;-) (...as Bruno implies, setattr(), len() et al can be and should be viewed as generic functions. A specific Pytho

Re: use str as variable name

2008-09-04 Thread Nick Craig-Wood
Mathieu Prevot <[EMAIL PROTECTED]> wrote: > Hi, > > I have a program that take a word as argument, and I would like to > link this word to a class variable. > > eg. > class foo(): >width = 10 >height = 20 > > a=foo() > arg='height' > a.__argname__= new_value Not quite sure what

Re: use str as variable name

2008-09-04 Thread Bruno Desthuilliers
Mathieu Prevot a écrit : 2008/9/4 Chris Rebert <[EMAIL PROTECTED]>: (snip) You're looking for the setattr() built-in function. In this exact case: setattr(a, arg, new_value) This is probably covered in the Python tutorial, please read it. Regards, Chris Indeed. I'll use: a.__setattr__

Re: use str as variable name

2008-09-04 Thread Fredrik Lundh
Mathieu Prevot wrote: I'll use: a.__setattr__(height, new_value) that's an implementation detail. please use setattr() instead, like everyone else. -- http://mail.python.org/mailman/listinfo/python-list

Re: use str as variable name

2008-09-04 Thread Mathieu Prevot
2008/9/4 Chris Rebert <[EMAIL PROTECTED]>: > On Thu, Sep 4, 2008 at 12:25 AM, Mathieu Prevot > <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I have a program that take a word as argument, and I would like to >> link this word to a class variable. >> >> eg. >> class foo(): > > You should subclass 'object'

Re: use str as variable name

2008-09-04 Thread Gabriel Genellina
En Thu, 04 Sep 2008 04:25:37 -0300, Mathieu Prevot <[EMAIL PROTECTED]> escribi�: I have a program that take a word as argument, and I would like to link this word to a class variable. eg. class foo(): width = 10 height = 20 a=foo() arg='height' a.__argname__= new_value rather than : if

Re: use str as variable name

2008-09-04 Thread Fredrik Lundh
Mathieu Prevot wrote: I have a program that take a word as argument, and I would like to link this word to a class variable. eg. class foo(): width = 10 height = 20 a=foo() arg='height' a.__argname__= new_value rather than : if arg == 'height': a.height = new_value elif arg == 'width';

Re: use str as variable name

2008-09-04 Thread Chris Rebert
On Thu, Sep 4, 2008 at 12:25 AM, Mathieu Prevot <[EMAIL PROTECTED]> wrote: > Hi, > > I have a program that take a word as argument, and I would like to > link this word to a class variable. > > eg. > class foo(): You should subclass 'object', so that should be: class Foo(object): > width = 1

use str as variable name

2008-09-04 Thread Mathieu Prevot
Hi, I have a program that take a word as argument, and I would like to link this word to a class variable. eg. class foo(): width = 10 height = 20 a=foo() arg='height' a.__argname__= new_value rather than : if arg == 'height': a.height = new_value elif arg == 'width'; a.width = new_val