Re: Differences between obj.attribute and getattr(obj, "attribute")

2013-12-11 Thread Johannes Schneider
thank you guys. On 11.12.2013 10:36, Chris Angelico wrote: 2013/12/11 Johannes Schneider : can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, "attribute")? Is there a special reason or advantage when using getattr? You use getatt

Re: Differences between obj.attribute and getattr(obj, "attribute")

2013-12-11 Thread Chris Angelico
On Wed, Dec 11, 2013 at 8:30 PM, Jurko Gospodnetić wrote: > Also, you can not test whether an object has an attribute when using the > object.attribute access method without raising/catching an exception and > then it can be hard to make sure no other code caused the exception. It's pretty easy

Re: Differences between obj.attribute and getattr(obj, "attribute")

2013-12-11 Thread Chris Angelico
2013/12/11 Johannes Schneider : > can somebody explain me the difference between accessing attributes via > obj.attribute and getattr(obj, "attribute")? > > Is there a special reason or advantage when using getattr? You use getattr when the attribute name comes from a

Re: Differences between obj.attribute and getattr(obj, "attribute")

2013-12-11 Thread Jurko Gospodnetić
Hi. On 11.12.2013. 9:23, Johannes Schneider wrote: can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, "attribute")? Is there a special reason or advantage when using getattr? You can not use obj.attribute if you have the word

Differences between obj.attribute and getattr(obj, "attribute")

2013-12-11 Thread Johannes Schneider
Hi list, can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, "attribute")? Is there a special reason or advantage when using getattr? bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228

Re: using getattr/setattr for local variables in a member function

2013-11-21 Thread Gregory Ewing
Catherine M Moroney wrote: is there some way to use getattr/setattr to access the local variables specific to a given function? No, because those variables don't even exist when there isn't a call to the function in progress. Your example suggests that, instead of local variables,

Re: using getattr/setattr for local variables in a member function

2013-11-21 Thread Ethan Furman
On 11/21/2013 06:02 PM, Dave Angel wrote: Catherine Moroney wrote: If I have a class that has some member functions, and all the functions define a local variable of the same name (but different type), is there some way to use getattr/setattr to access the local variables specific to a given

Re: using getattr/setattr for local variables in a member function

2013-11-21 Thread Dave Angel
On Fri, 22 Nov 2013 00:52:21 +, MRAB wrote: > If I have a class that has some member functions, and all the functions > define a local variable of the same name (but different type), is there > some way to use getattr/setattr to access the local variables specific >

Re: using getattr/setattr for local variables in a member function

2013-11-21 Thread Ned Batchelder
On Thursday, November 21, 2013 6:12:10 PM UTC-5, Catherine M Moroney wrote: > Hello, > > If I have a class that has some member functions, and all the functions > define a local variable of the same name (but different type), is there > some way to use getattr/setattr to a

Re: using getattr/setattr for local variables in a member function

2013-11-21 Thread MRAB
On 21/11/2013 23:12, Catherine M Moroney wrote: Hello, If I have a class that has some member functions, and all the functions define a local variable of the same name (but different type), is there some way to use getattr/setattr to access the local variables specific to a given function

using getattr/setattr for local variables in a member function

2013-11-21 Thread Catherine M Moroney
Hello, If I have a class that has some member functions, and all the functions define a local variable of the same name (but different type), is there some way to use getattr/setattr to access the local variables specific to a given function? Obviously there's no need to do this fo

Re: getattr and method name

2011-10-02 Thread Roy Smith
ackageSocketBindError sure beats IOError when it comes to trying to figure out what went wrong. 2) As much as possible, keep your try blocks short. In the original example, we've got: try: functionstring = args[2] callfunction = getattr(self, functionstring.split

Re: getattr and method name

2011-10-02 Thread Gary Herron
On 10/02/2011 05:24 PM, Kevin Walzer wrote: Turns out the error was a typo in the actual method being called...*faceinhands* Sorry for the noise. But this is a great example of why you should not use a naked except clause. As stated, your code will execute the except clause for *any* kin

Re: getattr and method name

2011-10-02 Thread Kevin Walzer
Turns out the error was a typo in the actual method being called...*faceinhands* Sorry for the noise. -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list

Re: getattr and method name

2011-10-02 Thread Steven D'Aprano
On Sun, 02 Oct 2011 18:02:05 -0400, Kevin Walzer wrote: > I'm seeing a very odd error in an application I'm developing using > Python 2.7.2, on Mac OS 10.7. > > This application uses a wrapper method to look up other method names via > getattr and then call those metho

Re: getattr and method name

2011-10-02 Thread Terry Reedy
On 10/2/2011 6:02 PM, Kevin Walzer wrote: I'm seeing a very odd error in an application I'm developing using Python 2.7.2, on Mac OS 10.7. This application uses a wrapper method to look up other method names via getattr and then call those methods. I have not previously had an issue

Re: getattr and method name

2011-10-02 Thread Chris Rebert
On Sun, Oct 2, 2011 at 3:02 PM, Kevin Walzer wrote: > I'm seeing a very odd error in an application I'm developing using Python > 2.7.2, on Mac OS 10.7. > > This application uses a wrapper method to look up other method names via > getattr and then call those methods. I h

getattr and method name

2011-10-02 Thread Kevin Walzer
I'm seeing a very odd error in an application I'm developing using Python 2.7.2, on Mac OS 10.7. This application uses a wrapper method to look up other method names via getattr and then call those methods. I have not previously had an issue with this name, but for some r

Re: Get a method instance through 'getattr' but not superclass's method

2010-04-03 Thread Gabriel Genellina
Please reply inline; top posting is harder to read. On Fri, Mar 12, 2010 at 12:15 AM, Gabriel Genellina wrote: En Thu, 11 Mar 2010 01:47:30 -0300, Radhakrishna Bhat escribió: I am using getattr to get a method instance from a class. But it also returns methods from the superclass. How to

Re: Get a method instance through 'getattr' but not superclass's method

2010-04-03 Thread Radhakrishna Bhat
Thu, 11 Mar 2010 01:47:30 -0300, Radhakrishna Bhat > escribió: > > > I am using getattr to get a method instance from a class. But it also >> returns methods from the superclass. How to detect if an attribute is from >> superclass? >> > > You may look it up dir

Re: Get a method instance through 'getattr' but not superclass's method

2010-03-11 Thread Gabriel Genellina
En Thu, 11 Mar 2010 01:47:30 -0300, Radhakrishna Bhat escribió: I am using getattr to get a method instance from a class. But it also returns methods from the superclass. How to detect if an attribute is from superclass? You may look it up directly in the class dictionary (__dict__

Re: Get a method instance through 'getattr' but not superclass's method

2010-03-11 Thread Radhakrishna Bhat
oblem. -Radhakrishna On Thu, Mar 11, 2010 at 6:12 PM, Steve Holden wrote: > Radhakrishna Bhat wrote: > > I am using getattr to get a method instance from a class. But it also > > returns methods from the superclass. How to detect if an attribute is > > from superclass? >

Re: Get a method instance through 'getattr' but not superclass's method

2010-03-11 Thread Steve Holden
Radhakrishna Bhat wrote: > I am using getattr to get a method instance from a class. But it also > returns methods from the superclass. How to detect if an attribute is > from superclass? > You could try, if x is in instance, looking to see whether the name is defined in x.__clas

Get a method instance through 'getattr' but not superclass's method

2010-03-10 Thread Radhakrishna Bhat
I am using getattr to get a method instance from a class. But it also returns methods from the superclass. How to detect if an attribute is from superclass? -Radhakrishna -- http://mail.python.org/mailman/listinfo/python-list

Re: Interesting things of 'getattr' and 'setattr'

2009-12-15 Thread Stefan Behnel
Red Forks, 15.12.2009 13:19: > I don't know it is a feature, or implement detail: > > >>> class C(object): pass > ... > >>> c = C() > >>> setattr(c, ' ', 3) > >>> getattr(c, ' ') > 3 > >>> setattr(c,

Interesting things of 'getattr' and 'setattr'

2009-12-15 Thread Red Forks
I don't know it is a feature, or implement detail: >>> class C(object): pass ... >>> c = C() >>> setattr(c, ' ', 3) >>> getattr(c, ' ') 3 >>> setattr(c, 'with blank', 4) >>> getattr(c, 'with blank'

Re: getattr problem

2009-12-02 Thread Bruno Desthuilliers
foo = ("bar", "baaz, back") >>> "bar" in foo True >>> "baaz" in foo False >>> """ storesTables.append(table) for table in storesTables: You don't need two loops here - you could as well proceed as you go,

Re: getattr problem

2009-12-01 Thread Victor Subervi
mport options >> storesTables = [] >> junkStores = string.join(addStore(), ', ') >> for table in optionsTables(): >> if table not in ('particulars', junkStores): >>storesTables.append(table) >> for table in storesTables: >> try: >>fn

Re: getattr problem

2009-12-01 Thread Jean-Michel Pichavant
rs', junkStores): storesTables.append(table) for table in storesTables: try: fn = getattr(options, table) print fn() except: pass I need to change the obvious line to this or something similar (that actually works): fn = getattr(options, '%s("names")' % table) Tha

getattr problem

2009-12-01 Thread Victor Subervi
es.append(table) for table in storesTables: try: fn = getattr(options, table) print fn() except: pass I need to change the obvious line to this or something similar (that actually works): fn = getattr(options, '%s("names")' % table) That is, I need to pass the

Re: Need help to understand a getattr syntax.

2009-11-24 Thread Diez B. Roggisch
NMarcu wrote: > Hello all, > I need some help to understand a getattr syntax. The syntax is: > > try: > getattr(self, command)(cursor, row) > except Exception, e: > print "Action failed : '%s'" % command > raise e > > I don

Need help to understand a getattr syntax.

2009-11-24 Thread NMarcu
Hello all, I need some help to understand a getattr syntax. The syntax is: try: getattr(self, command)(cursor, row) except Exception, e: print "Action failed : '%s'" % command raise e I don't understand why is not like this: a = getattr(), and what ar

Re: getattr on a function

2009-04-27 Thread Terry Reedy
Mr SZ wrote: Hi all, Is it possible to call functions using getattr. I have written a simple script with functions that call either SSL, TLS or plain functionality. something like: def func(): ... def funcSSL(): ... def funcTLS(): funcs = {'none':func, 'SSL':fu

Re: getattr on a function

2009-04-27 Thread John Machin
On Apr 28, 2:30 am, Mr SZ wrote: > Hi all, > > Is it possible to call functions using getattr. I have written a simple > script with functions that call either SSL, TLS or plain functionality. > > something like: > def func(): >   ... > > def funcSSL(): >   ... &

Re: getattr on a function

2009-04-27 Thread Peter Otten
Mr SZ wrote: > Is it possible to call functions using getattr. I have written a simple > script with functions that call either SSL, TLS or plain functionality. > > something like: > def func(): > ... > > def funcSSL(): > ... > > def funcTLS(): > ..

getattr on a function

2009-04-27 Thread Mr SZ
Hi all, Is it possible to call functions using getattr. I have written a simple script with functions that call either SSL, TLS or plain functionality. something like: def func(): ... def funcSSL(): ... def funcTLS(): ... Now, based on my args I would like to call either one of them

Re: setattr and getattr, when to use?

2008-08-26 Thread Bruno Desthuilliers
Jason Scheirer a écrit : (snip) The 5% of your time when you are doing metaprogramming or other abuses of the object system are when you use get/setattr. What makes you label "metaprogramming" and get/setattr as "abuses" ??? -- http://mail.python.org/mailman/listinfo/python-list

Re: setattr and getattr, when to use?

2008-08-23 Thread Steven D'Aprano
On Fri, 22 Aug 2008 20:50:17 -0700, maestro wrote: > Why are these functions there? Is it somehow more idiomatic to use than > to do obj.field ? Heavens no!!! Using setattr and getattr is *less* idiomatic. > Is there something you can with them that you can't by obj.fie

Re: setattr and getattr, when to use?

2008-08-22 Thread Jason Scheirer
ith them that you can't by obj.field > > reference? > > You can generate them dynamically from strings. In some cases you > don't know until runtime what attributes you want to pull: > > def show_insides(obj): >   for attr in dir(obj): >     print "Attribute %r: %

Re: setattr and getattr, when to use?

2008-08-22 Thread Jason Scheirer
ings. In some cases you don't know until runtime what attributes you want to pull: def show_insides(obj): for attr in dir(obj): print "Attribute %r: %r" % (attr, getattr(obj, attr)) class hello(object): a = 1 b = 2 class goodbye(object): c = 1 d = 500 pri

setattr and getattr, when to use?

2008-08-22 Thread maestro
Why are these functions there? Is it somehow more idiomatic to use than to do obj.field ? Is there something you can with them that you can't by obj.field reference? -- http://mail.python.org/mailman/listinfo/python-list

Re: getattr() on nested functions?

2008-08-21 Thread castironpi
func): >      dispatch = func() >      def _task(action, *args): >          return resultToXml(dispatch[action](*args)) >      _task.__name__ = _task.func_name = func.__name__ >     return _task > > @_make_task > def _task1(): >      def request(params): >          pass >    

Re: getattr() on nested functions?

2008-08-21 Thread Bruno Desthuilliers
Gabriel Rossetti a écrit : Bruno Desthuilliers wrote: Gabriel Rossetti a écrit : Terry Reedy wrote: (snip) Unlike the class approach, this requires recreating the constant functions and dict with each call to _test. Quick to write but a bit 'dirty', in my opinion. Another standard idiom is

Re: getattr() on nested functions?

2008-08-21 Thread Gabriel Rossetti
Bruno Desthuilliers wrote: Gabriel Rossetti a écrit : Terry Reedy wrote: (snip) Unlike the class approach, this requires recreating the constant functions and dict with each call to _test. Quick to write but a bit 'dirty', in my opinion. Another standard idiom is to set up the constants ou

Re: getattr() on nested functions?

2008-08-21 Thread Bruno Desthuilliers
Gabriel Rossetti a écrit : Terry Reedy wrote: (snip) Unlike the class approach, this requires recreating the constant functions and dict with each call to _test. Quick to write but a bit 'dirty', in my opinion. Another standard idiom is to set up the constants outside the function: def re

Re: getattr() on nested functions?

2008-08-21 Thread Gabriel Rossetti
s): pass def update(self, params, values): pass def delete(self, params): pass def __call__(self, action, *args): return resultToXml(getattr(self, action)(*args)) _test = _Test() Yes, very hackish :-) No, not at all hackish, but one standard way to do what you want.

Re: getattr() on nested functions?

2008-08-20 Thread Terry Reedy
s): pass def delete(self, params): pass def __call__(self, action, *args): return resultToXml(getattr(self, action)(*args)) _test = _Test() Yes, very hackish :-) No, not at all hackish, but one standard way to do what you want. locals() is your friend. def _test(self, ac

Re: getattr() on nested functions?

2008-08-20 Thread Gabriel Rossetti
Bruno Desthuilliers wrote: Gabriel Rossetti a écrit : Hello, I can't get getattr() to return nested functions, Of course. Nested functions are not attributes of their container function. Ok I tried this : >>> def toto(): ... def titi(): ... pass ...

Re: getattr() on nested functions?

2008-08-20 Thread Gabriel Rossetti
Gabriel Genellina wrote: En Wed, 20 Aug 2008 05:34:38 -0300, Gabriel Rossetti <[EMAIL PROTECTED]> escribi�: I can't get getattr() to return nested functions, I tried this : >>> def toto(): ... def titi(): ... pass ... f = getattr(toto, "t

Re: getattr() on nested functions?

2008-08-20 Thread Bruno Desthuilliers
Gabriel Rossetti a écrit : Hello, I can't get getattr() to return nested functions, Of course. Nested functions are not attributes of their container function. I tried this : >>> def toto(): ... def titi(): ... pass ... f = getattr(toto, "titi&qu

Re: getattr() on nested functions?

2008-08-20 Thread Gabriel Genellina
En Wed, 20 Aug 2008 05:34:38 -0300, Gabriel Rossetti <[EMAIL PROTECTED]> escribi�: I can't get getattr() to return nested functions, I tried this : >>> def toto(): ... def titi(): ... pass ... f = getattr(toto, "titi") ... print str(f) .

Re: getattr() on nested functions?

2008-08-20 Thread Hrvoje Niksic
Gabriel Rossetti <[EMAIL PROTECTED]> writes: > I can't get getattr() to return nested functions, I tried this : > >>>> def toto(): > ... def titi(): > ... pass > ... f = getattr(toto, "titi") > ... print str(f) > ... &g

getattr() on nested functions?

2008-08-20 Thread Gabriel Rossetti
Hello, I can't get getattr() to return nested functions, I tried this : >>> def toto(): ... def titi(): ... pass ... f = getattr(toto, "titi") ... print str(f) ... >>> toto() Traceback (most recent call last): File "&q

Re: getattr nested attributes

2008-08-15 Thread Fredrik Lundh
Gregor Horvath wrote: Thank's, but this does not work for this case: class A(object): test = "test" class B(object): a = [A(),] In [70]: reduce(getattr, "a[0].test".split("."), B)

Re: getattr nested attributes

2008-08-15 Thread Paul Boddie
On 15 Aug, 10:35, Gregor Horvath <[EMAIL PROTECTED]> wrote: > > : type object 'B' has no attribute > 'a.test' You have to realise that attributes can have names beyond those supported by the usual attribute access syntax. For example: class C: pass setat

Re: getattr nested attributes

2008-08-15 Thread Steven D'Aprano
On Fri, 15 Aug 2008 11:12:04 +0200, Gregor Horvath wrote: > Peter Otten schrieb: > >> make your own function that loops over the attributes, or spell it >> >>>>> reduce(getattr, "a.test".split("."), B) >> 'test' >>

Re: getattr nested attributes

2008-08-15 Thread Wojtek Walczak
On Fri, 15 Aug 2008 11:12:04 +0200, Gregor Horvath wrote: > Thank's, but this does not work for this case: > > class A(object): > test = "test" > > class B(object): > a = [A(),] > > In [70]:

Re: getattr nested attributes

2008-08-15 Thread Peter Otten
Gregor Horvath wrote: > Peter Otten schrieb: > >> make your own function that loops over the attributes, or spell it >> >>>>> reduce(getattr, "a.test".split("."), B) >> 'test' >> > > Thank's, but this does

Re: getattr nested attributes

2008-08-15 Thread Gregor Horvath
Peter Otten schrieb: make your own function that loops over the attributes, or spell it reduce(getattr, "a.test".split("."), B) 'test' Thank's, but this does not work for this case: class A(object): test = "test" class B(object): a

Re: getattr nested attributes

2008-08-15 Thread Peter Otten
Gregor Horvath wrote: > Hi, > > class A(object): > test = "test" > > class B(object): > a = A() > > > In [36]: B.a.test > Out[36]: 'test' > > In [37]: getattr(B, "a.test") >

Re: getattr nested attributes

2008-08-15 Thread Christian Heimes
Gregor Horvath wrote: any help? I guess you missunderstood the sentence "For example, getattr(x, 'foobar') is equivalent to x.foobar.". getattr(x, "foo.bar") is not equivalant to x.foo.bar. -- http://mail.python.org/mailman/listinfo/python-list

getattr nested attributes

2008-08-15 Thread Gregor Horvath
Hi, class A(object): test = "test" class B(object): a = A() In [36]: B.a.test Out[36]: 'test' In [37]: getattr(B, "a.test") --- Traceback (most recent call last) / i

Re: extend getattr()

2008-06-27 Thread Jared Grubb
Error: if '.' in name: attrs = name.split('.') first = object.__getattribute__(self, attrs[0]) return getattr(first, '.'.join(attrs[1:])) raise >>> a = A() >>> a.b = A() >>> a.b.c = A() >>&

Re: extend getattr()

2008-06-26 Thread George Sakkis
> > > class B(object): > > def __init__(self): > > c = C() > > note you're just defining some local variables here, should be self.b = B() > and self.c = C(). > > > class C(object): > > def __init__(self): > > pass >

Re: extend getattr()

2008-06-26 Thread Cédric Lucantis
e just defining some local variables here, should be self.b = B() and self.c = C(). > class C(object): > def __init__(self): > pass > > and now i wanna do something like this: > > a=A() > c=getattr(a, 'b.c') > > I know this doesn't work, but wha

Re: extend getattr()

2008-06-26 Thread Gerhard Häring
Rotlaus wrote: Hello, lets assume i have some classes: [...] a=A() c=getattr(a, 'b.c') I know this doesn't work, but what can i do to get this or a similar functionality to get it work for this sample and for even more nested classes? Just recursively apply the getattr(), li

extend getattr()

2008-06-26 Thread Rotlaus
Hello, lets assume i have some classes: class A(object): def __init__(self): b = B() class B(object): def __init__(self): c = C() class C(object): def __init__(self): pass and now i wanna do something like this: a=A() c=getattr(a, 'b.c') I

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Bruno Desthuilliers
Erik Max Francis a écrit : > Dave Kuhlman wrote: > >> Basically, the above code is saying that foo.foobar is not the same as >> getattr(foo, 'foobar'). > > Python promises that the behavior is the same. It does not promise that > the _objects_ will be th

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Bruno Desthuilliers
Mel a écrit : (snip) > (What Diez said.) From what I've seen, f.bar creates a bound method > object by taking the unbound method Foo.bar and binding its first > parameter with f. Nope. it's Foo.__dict__['bar'] (that is, the function bar defined in the namespace of class Foo) that creates a bo

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Bruno Desthuilliers
Dave Kuhlman a écrit : > Arnaud Delobelle wrote: > >> 4. Both points above follow from the fact that foo.bar is really a >> function call that returns a (potentially) new object: in fact what >> really happens is something like > > Arnaud and Imri, too - > > No. foo.bar is *not* really a funct

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Peter Otten
unt ... count = -1 ... >>> class Foo(object): ... bar = Bar() ... def __repr__(self): return "foo" ... >>> foo = Foo() >>> foo.bar __get__(foo, ) 0 >>> foo.bar __get__(foo, ) 1 >>> foo.bar __get__(foo, ) 2 >>> getattr(foo, "bar") __get__(foo, ) 3 Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: getattr/setattr still ASCII-only, not Unicode - blows up SGMLlib from BeautifulSoup

2008-03-13 Thread Carl Banks
On Mar 14, 1:53 am, John Nagle <[EMAIL PROTECTED]> wrote: > John Machin wrote: > > On Mar 14, 5:38 am, John Nagle <[EMAIL PROTECTED]> wrote: > >>Just noticed, again, that getattr/setattr are ASCII-only, and don't > >> support > >> Unicode.

Re: getattr/setattr still ASCII-only, not Unicode - blows up SGMLlib from BeautifulSoup

2008-03-13 Thread John Nagle
John Machin wrote: > On Mar 14, 5:38 am, John Nagle <[EMAIL PROTECTED]> wrote: >>Just noticed, again, that getattr/setattr are ASCII-only, and don't >> support >> Unicode. >> >>SGMLlib blows up because of this when faced with a Unicode end tag:

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread castironpi
On Mar 13, 8:15 pm, [EMAIL PROTECTED] wrote: > On Mar 13, 7:45 pm, [EMAIL PROTECTED] wrote: > > > > > > > On Mar 13, 7:18 pm, Mel <[EMAIL PROTECTED]> wrote: > > > > Diez B. Roggisch wrote: > > > >> My understanding is that foo.bar does *not* create a new object. > > > > > Your understanding is not

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread castironpi
On Mar 13, 7:45 pm, [EMAIL PROTECTED] wrote: > On Mar 13, 7:18 pm, Mel <[EMAIL PROTECTED]> wrote: > > > > > > > Diez B. Roggisch wrote: > > >> My understanding is that foo.bar does *not* create a new object. > > > > Your understanding is not correct. > > > >>  All it > > >> does is return the value

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread castironpi
On Mar 13, 7:18 pm, Mel <[EMAIL PROTECTED]> wrote: > Diez B. Roggisch wrote: > >> My understanding is that foo.bar does *not* create a new object. > > > Your understanding is not correct. > > >>  All it > >> does is return the value of the bar attribute of object foo.  What new > >> object is being

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread Mel
Diez B. Roggisch wrote: >> My understanding is that foo.bar does *not* create a new object. > > Your understanding is not correct. > >> All it >> does is return the value of the bar attribute of object foo. What new >> object is being created? > > A bound method. This happens through the descr

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread Arnaud Delobelle
On Mar 13, 11:29 pm, Dave Kuhlman <[EMAIL PROTECTED]> wrote: > Arnaud Delobelle wrote: > > > 4.  Both points above follow from the fact that foo.bar is really a > > function call that returns a (potentially) new object: in fact what > > really happens is something like > > Arnaud and Imri, too - >

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread castironpi
> > Basically, the above code is saying that foo.foobar is not the same as > > getattr(foo, 'foobar'). > > > What gives?  This breaks my understanding of id(), the is operator, and > > getattr(). > > 4.  Both points above follow from the fact that foo.bar

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread Diez B. Roggisch
> My understanding is that foo.bar does *not* create a new object. Your understanding is not correct. > All it > does is return the value of the bar attribute of object foo. What new > object is being created? A bound method. This happens through the descriptor-protocol. Please see this examp

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread Erik Max Francis
Dave Kuhlman wrote: > Basically, the above code is saying that foo.foobar is not the same as > getattr(foo, 'foobar'). Python promises that the behavior is the same. It does not promise that the _objects_ will be the same, which is what `is` determines. That is, you'

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread Dave Kuhlman
Arnaud Delobelle wrote: > > 4. Both points above follow from the fact that foo.bar is really a > function call that returns a (potentially) new object: in fact what > really happens is something like Arnaud and Imri, too - No. foo.bar is *not* really a function/method call. > > Foo.__di

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread Arnaud Delobelle
On Mar 13, 10:06 pm, Dave Kuhlman <[EMAIL PROTECTED]> wrote: > The following code has me mystified: > > In [4]: class A(object): >    ...:     def show(self): >    ...:         print 'hello' >    ...: >    ...: > In [5]: a = A() > In [6]: > In [7]: x

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread Imri Goldberg
Dave Kuhlman wrote: > The following code has me mystified: > > In [4]: class A(object): >...: def show(self): >...: print 'hello' >...: >...: > In [5]: a = A() > In [6]: > In [7]: x = a.show > In [8]: y = getattr(a, 's

getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-13 Thread Dave Kuhlman
The following code has me mystified: In [4]: class A(object): ...: def show(self): ...: print 'hello' ...: ...: In [5]: a = A() In [6]: In [7]: x = a.show In [8]: y = getattr(a, 'show') In [9]: x Out[9]: > In [10]: y Out[10]: > In [11]: In [12]:

Re: getattr/setattr still ASCII-only, not Unicode - blows up SGMLlib from BeautifulSoup

2008-03-13 Thread John Machin
On Mar 14, 5:38 am, John Nagle <[EMAIL PROTECTED]> wrote: >Just noticed, again, that getattr/setattr are ASCII-only, and don't support > Unicode. > >SGMLlib blows up because of this when faced with a Unicode end tag: > > File "/usr/local/lib/p

Re: getattr/setattr still ASCII-only, not Unicode - blows up SGMLlibfrom BeautifulSoup

2008-03-13 Thread Terry Reedy
"John Nagle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | Just noticed, again, that getattr/setattr are ASCII-only, and don't support | Unicode. | | SGMLlib blows up because of this when faced with a Unicode end tag: | | File "/usr/local/lib/pytho

getattr/setattr still ASCII-only, not Unicode - blows up SGMLlib from BeautifulSoup

2008-03-13 Thread John Nagle
Just noticed, again, that getattr/setattr are ASCII-only, and don't support Unicode. SGMLlib blows up because of this when faced with a Unicode end tag: File "/usr/local/lib/python2.5/sgmllib.py", line 353, in finish_endtag method = getattr(sel

Re: getattr() question

2007-12-22 Thread Sledge
ed until run time. I have it > > loading the module correctly, but when I use getattr to access the > > class and its attributes everything works except that I get additional > > unwanted output. The code > > > testclass.py: > > > #!/usr/bin/python > > >

Re: getattr() question

2007-12-22 Thread John Machin
On Dec 23, 10:39 am, Sledge <[EMAIL PROTECTED]> wrote: > Hi. > > I am trying to dynamically load a class and attributes at run time. I > do not know what classes will be referenced until run time. I have it > loading the module correctly, but when I use getattr to acces

getattr() question

2007-12-22 Thread Sledge
Hi. I am trying to dynamically load a class and attributes at run time. I do not know what classes will be referenced until run time. I have it loading the module correctly, but when I use getattr to access the class and its attributes everything works except that I get additional unwanted

Re: setattr getattr confusion

2007-12-08 Thread Donn Ingle
Thanks Bruno, I had to keep coding, so I used the long form [Object.subobject.property = blah] anyway. It's long-winded, but unambiguous. \d -- http://mail.python.org/mailman/listinfo/python-list

Re: setattr getattr confusion

2007-12-08 Thread Bruno Desthuilliers
Donn Ingle a écrit : >>class Key(object): >>def __init__self): >>self.__dict__['props'] = KeyProps() > > Okay - that's weird. No, that's coherent. The default behavior (I mean, when there's no descriptor involved etc) of __setattr__ is to store attributes in instance.__dict__. So as long a you

Re: setattr getattr confusion

2007-12-08 Thread Donn Ingle
> class Key(object): > def __init__self): > self.__dict__['props'] = KeyProps() Okay - that's weird. Is there another way to spin this? > def __setattr__(self,var,val): > setattr(self.props,var,val) Perhaps by changing this one? \d -- http://mail.python.org/mailman/listinfo/python-list

Re: setattr getattr confusion

2007-12-08 Thread Steven D'Aprano
On Sat, 08 Dec 2007 14:26:00 +0200, Donn Ingle wrote: >> So you might want to describe your use-case. > Um.. I wanted an object with Key to hold other data. I wanted a way to > set that *other* data within Key without having to specify the "object > in-between" everytime. That's called "automatic

Re: setattr getattr confusion

2007-12-08 Thread Carl Banks
On Dec 8, 6:06 am, Donn Ingle <[EMAIL PROTECTED]> wrote: > Hi, > Here's some code, it's broken: > > class Key( object ): > def __init__(self): > self.props = KeyProps() > def __getattr__(self, v): > return getattr( self.prop

Re: setattr getattr confusion

2007-12-08 Thread Donn Ingle
> So you might want to describe your use-case. Um.. I wanted an object with Key to hold other data. I wanted a way to set that *other* data within Key without having to specify the "object in-between" everytime. k1.x = "ni!" should perform: k1.props.x = "ni!" and print k1.x should perform: print

Re: setattr getattr confusion

2007-12-08 Thread James Stroud
Donn Ingle wrote: > Hi, > Here's some code, it's broken: > > > class Key( object ): > def __init__(self): > self.props = KeyProps() > def __getattr__(self, v): > return getattr( self.props,v ) > def __setattr__(self,var,val):

setattr getattr confusion

2007-12-08 Thread Donn Ingle
Hi, Here's some code, it's broken: class Key( object ): def __init__(self): self.props = KeyProps() def __getattr__(self, v): return getattr( self.props,v ) def __setattr__(self,var,val): object.__setattr__(self.props,var,val) class KeyPr

Re: Can you use -getattr- to get a function in the current module?

2007-09-03 Thread Sergio Correia
Alex, Gabriel, Thanks for the reply. Works great! On 9/3/07, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > En Mon, 03 Sep 2007 20:13:43 -0300, Sergio Correia > <[EMAIL PROTECTED]> escribi�: > > > # Module spam.py > > > > import eggs > > > > pr

  1   2   >