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
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
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
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
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
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
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
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
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
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}
...
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,
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
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
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
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
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
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
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
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
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)
...
>>
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)
...
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
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
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
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")
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):
>
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)
>
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):
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
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
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
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
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
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
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
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
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/
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
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
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
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
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 -
>
> > 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
> 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
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
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
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 [
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
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
"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,
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
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
> 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
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
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
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
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?
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
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
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
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):
...
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
> 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]
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
> 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.
> > 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
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
[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
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
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
[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
> 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
[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
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
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
[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
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
77 matches
Mail list logo