Re: getattr and method name

2011-10-02 Thread Roy Smith
In article , Gary Herron wrote: > 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 state

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 methods. I have not previously ha

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 with this na

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 have not previously had an

Re: getattr problem

2009-12-02 Thread Bruno Desthuilliers
Victor Subervi wrote: (NB : answering to the OP - the post didn't show up on clpy) Hi; I have the following code that execute without a problem: Fine. But it fails to execute here - ImportError on the 3rd line ("options"), NameErrors on the 4th line ("addStore") and 5th line ("optionTables

Re: getattr problem

2009-12-01 Thread Victor Subervi
On Tue, Dec 1, 2009 at 3:17 PM, Jean-Michel Pichavant < jeanmic...@sequans.com> wrote: > Victor Subervi wrote: > >> Hi; >> I have the following code that execute without a problem: >> >> import sys,os >> sys.path.append(os.getcwd()) >> import options >> storesTables = [] >> junkStores = string.joi

Re: getattr problem

2009-12-01 Thread Jean-Michel Pichavant
Victor Subervi wrote: Hi; I have the following code that execute without a problem: import sys,os sys.path.append(os.getcwd()) import options storesTables = [] junkStores = string.join(addStore(), ', ') for table in optionsTables(): if table not in ('particulars', junkStores): storesTables

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':funcSSL, 'TLS':funcTLS} ...

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(): >   ... > > def funcTLS(): >   ... > > Now,

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(): > ... > > Now, based on my args I would lik

Re: getattr() on nested functions?

2008-08-21 Thread castironpi
On Aug 21, 10:14 am, Bruno Desthuilliers wrote: > 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

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
Terry Reedy wrote: Gabriel Rossetti wrote: Bruno Desthuilliers wrote: Gabriel Rossetti a écrit : I thought that since functions are objects, that I could obtain it's nested functions. Well, there's probably a very hackish way, but it's not worth the pain. What Bruno meant here, I belie

Re: getattr() on nested functions?

2008-08-20 Thread Terry Reedy
Gabriel Rossetti wrote: Bruno Desthuilliers wrote: Gabriel Rossetti a écrit : I thought that since functions are objects, that I could obtain it's nested functions. Well, there's probably a very hackish way, but it's not worth the pain. What Bruno meant here, I believe, is that there i

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 ... f = getattr(toto

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, "titi") ... print str(f) ... >>

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") ... print str(f) ...

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) ... >>> toto() Traceback (most

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) > ... toto() > Traceback (most recent call last): > File

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) --- Traceback (most recen

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 setattr(C, "x.y", 123) getattr(C, "x.y")

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' >> >> > Thank's, but this does not work for this case: > > class A(object): >

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]: reduce(getattr, "a[0].test".split("."), B) >

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 not work for this case: > > class A(object): > test = "test" > > class B(object):

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 = [A(),] In [70]: reduce(getattr, "a[0].test".s

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") > --- > Traceback (most recent

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

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 the same, which is what `is` determines. T

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
Dave Kuhlman 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 - > > No. foo.bar is *not* really a fun

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. > > >>SGMLlib blows up because of this when faced

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: >> >> File "/usr/local/lib/python2.5/

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 is really a > function call that returns a

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 not doing a useful test

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 = a.show > In [8]: y = getattr(a, 'show') > In [

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, 'show') > In [9]: x > Out[9]: > > In [10]: y > Out[10

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/python2.5/sgmllib.py", line 353, in finis

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/python2.5/sgmllib.py", line 353,

Re: getattr() question

2007-12-22 Thread Sledge
On Dec 22, 7:14 pm, John Machin <[EMAIL PROTECTED]> wrote: > 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 m

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 access the > class and its attri

Re: getattr/setattr q.

2007-04-03 Thread Paulo da Silva
> Yes, but you shouldn't unless you really need to. You're better off > rethinking your algorithm. I need it but inside a class. The idea is to pass an instance of a class (think of something like a record but with some methods inside) with "fields", whose names are not known in advance, to ano

Re: getattr/setattr q.

2007-04-03 Thread Steve Holden
Steven Bethard wrote: > Steve Holden wrote: >> You don't need setattr/getattr if you know in advance the name of the >> attribute you need to access and you can get a reference to the object >> whose attribute it is. So: >> >> >>> x = "Hello, Paulo" >> >>> import sys >> >>> sys.modules['__main

Re: getattr/setattr q.

2007-04-03 Thread Steven Bethard
Steve Holden wrote: > You don't need setattr/getattr if you know in advance the name of the > attribute you need to access and you can get a reference to the object > whose attribute it is. So: > > >>> x = "Hello, Paulo" > >>> import sys > >>> sys.modules['__main__'].x > 'Hello, Paulo' a.k.a

Re: getattr/setattr q.

2007-04-03 Thread Steve Holden
Paulo da Silva wrote: > Steven Bethard escreveu: >> Paulo da Silva wrote: > ... > >> If you're at the module level, you can do:: >> >> globals()['x'] = 10 >> >> If you're inside a function, you probably want to look for another way >> of doing what you're doing. >> >> What's the actual task yo

Re: getattr/setattr q.

2007-04-03 Thread Paulo da Silva
Steven Bethard escreveu: > Paulo da Silva wrote: ... > If you're at the module level, you can do:: > > globals()['x'] = 10 > > If you're inside a function, you probably want to look for another way > of doing what you're doing. > > What's the actual task you're trying to accomplish here?

Re: getattr/setattr q.

2007-04-03 Thread Paulo da Silva
7stud escreveu: > On Apr 2, 10:08 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote: >> Is it possible to use getattr/setattr for variables not inside >> classes...? > > What does the python documentation say about the definition of > setattr()? > I didn't read the full python documentation, yet! I ho

Re: getattr/setattr q.

2007-04-02 Thread Steven D'Aprano
On Tue, 03 Apr 2007 05:08:42 +0100, Paulo da Silva wrote: > Hi! > > In a class C, I may do setattr(C,'x',10). > > Is it possible to use getattr/setattr for variables not inside > classes or something equivalent? I mean with the same result as > exec("x=10"). Yes, but you shouldn't unless you re

Re: getattr/setattr q.

2007-04-02 Thread 7stud
On Apr 2, 10:08 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote: > Is it possible to use getattr/setattr for variables not inside > classes...? What does the python documentation say about the definition of setattr()? -- http://mail.python.org/mailman/listinfo/python-list

Re: getattr/setattr q.

2007-04-02 Thread Ben Finney
Paulo da Silva <[EMAIL PROTECTED]> writes: > In a class C, I may do setattr(C,'x',10). That would set an attribute on the class C, shared by all instances of that class. If you want to set an attribute on an instance, you need to do so on the instance object:: >>> class Foo(object): ...

Re: getattr/setattr q.

2007-04-02 Thread Steven Bethard
Paulo da Silva wrote: > In a class C, I may do setattr(C,'x',10). > > Is it possible to use getattr/setattr for variables not inside > classes or something equivalent? I mean with the same result as > exec("x=10"). If you're at the module level, you can do:: globals()['x'] = 10 If you're i

Re: getattr for modules not classes

2006-05-27 Thread Piet van Oostrum
> Heiko Wundram <[EMAIL PROTECTED]> (HW) schreef: >HW> from x import test as x >HW> print x.one >HW> print x.two >HW> print x.three Or replace test by x in x.py :=) -- Piet van Oostrum <[EMAIL PROTECTED]> URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4] Private email: [EMAIL PROTECTED]

Re: getattr for modules not classes

2006-05-26 Thread Heiko Wundram
Am Mittwoch 24 Mai 2006 15:43 schrieb Piet van Oostrum: > > Heiko Wundram <[EMAIL PROTECTED]> (HW) wrote: > > > >HW> y.py > >HW> --- > >HW> from x import test > >HW> print test.one > >HW> print test.two > >HW> print test.three > >HW> --- > > Or even: > import x > x = x.test > print x.one > prin

Re: getattr for modules not classes

2006-05-24 Thread Piet van Oostrum
> Heiko Wundram <[EMAIL PROTECTED]> (HW) wrote: >HW> y.py >HW> --- >HW> from x import test >HW> print test.one >HW> print test.two >HW> print test.three >HW> --- Or even: import x x = x.test print x.one print x.two print x.three -- Piet van Oostrum <[EMAIL PROTECTED]> URL: http://www.cs.uu.

Re: getattr for modules not classes

2006-05-22 Thread Daniel Nogradi
> > Is there something analogous to __getattr__ for modules? > > > > I know how to create a class that has attributes from a list and > > nothing else by overloading __getattr__ and making sure that the > > accessed attribute appears in my list. Now I would like to do the same > > with a module, sa

Re: getattr for modules not classes

2006-05-21 Thread Heiko Wundram
Am Sonntag 21 Mai 2006 21:52 schrieb Daniel Nogradi: > Is there something analogous to __getattr__ for modules? > > I know how to create a class that has attributes from a list and > nothing else by overloading __getattr__ and making sure that the > accessed attribute appears in my list. Now I woul

Re: getattr from local scope

2006-04-24 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > I know I can use eval, but I've always been told that if you're using > eval, you're doing it wrong. Also not using eval limits the scope damage > that can be caused by any errors in my application which could cause > the database to be poisoned. a more robust approach

Re: getattr from local scope

2006-04-23 Thread Edward Elliott
Alex Martelli wrote: > sys.modules[__name__].__dict__ may be more handily accessed by the > built-in function globals(). Well there you go. Glad it's not that awkward. -- http://mail.python.org/mailman/listinfo/python-list

Re: getattr from local scope

2006-04-23 Thread Alex Martelli
Edward Elliott <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Basically my application has a scheduler which stores names of functions > > defined in the "schedule" module in a database, to be run on certain > > days. Every night I call schedule.RunSchedule, which grabs all the rows on

Re: getattr from local scope

2006-04-23 Thread Edward Elliott
[EMAIL PROTECTED] wrote: > Basically my application has a scheduler which stores names of functions > defined in the "schedule" module in a database, to be run on certain > days. Every night I call schedule.RunSchedule, which grabs all the rows on > the database that have to be run now, and I want

Re: getattr

2005-09-30 Thread Fredrik Lundh
> if you want to control further accesses, your __getattr__ has to return a > proxy object, and use a suitable syntax to get the final value. message.insert(index, "your users have to ") -- http://mail.python.org/mailman/listinfo/python-list

Re: getattr

2005-09-30 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > Is there any way by which the __getattr__(self,attr) method can > determine that in > case a) attr == 'bar' is the final component in the reference unlike in > case b) where attr=='bar' is NOT the ultimate(final) component of > reference and is an intermediate component

Re: getattr() woes

2004-12-30 Thread Kamilche
Thomas Rast wrote: I've found out about a fundamental problem of attribute lookup, the hard way... Is there anything that can be done about this? It seems to me that the main problem is you're raising an AttributeError when an attribute is private. AttributeError is only raised when an attribute

Re: getattr() woes

2004-12-29 Thread Nicolas Fleury
David M. Cooke wrote: Ideally, I think the better way is if getattr, when raising AttributeError, somehow reused the old traceback (which would point out the original problem). I don't know how to do that, though. Maybe a solution could be to put the attribute name in the AttributeError exception

Re: getattr() woes

2004-12-28 Thread David M. Cooke
[EMAIL PROTECTED] (Aahz) writes: > In article <[EMAIL PROTECTED]>, > Thomas Rast <[EMAIL PROTECTED]> wrote: >> >>class dispatcher: >># ... >>def __getattr__(self, attr): >>return getattr(self.socket, attr) >> > import asyncore > class Peer(asyncore.dispatcher): >>... d

Re: getattr() woes

2004-12-28 Thread Aahz
In article <[EMAIL PROTECTED]>, Thomas Rast <[EMAIL PROTECTED]> wrote: > >I've found out about a fundamental problem of attribute lookup, the >hard way. Maybe. >asyncore.py uses the following code: > >class dispatcher: ># ... >def __getattr__(self, attr): >return getattr(self.soc