Re: eval function not working how i want it dag namn

2005-04-19 Thread Greg Ewing
robcarlton wrote: thanks. I'll use the getattr function now, and I think I understand where I went wrong with eval. I was thinking in Lisp where the lexical scope would mean that obj is defined The full story is actually more subtle. The name 'obj' *is* accessible from a nested scope if you do some

Re: eval function not working how i want it dag namn

2005-04-15 Thread robcarlton
thanks. I'll use the getattr function now, and I think I understand where I went wrong with eval. I was thinking in Lisp where the lexical scope would mean that obj is defined -- http://mail.python.org/mailman/listinfo/python-list

Re: eval function not working how i want it dag namn

2005-04-15 Thread Michael Hoffman
Peter Otten wrote: Michael Hoffman wrote: def list_members(obj) l = dir(obj) return map(lambda x : eval('obj.'+x), l) That works fine for me with Python 2.4. x.question = "Are you sure?" I should clarify. It works fine for me when I've already globally assigned obj to something else. D'oh! -- Mic

Re: eval function not working how i want it dag namn

2005-04-15 Thread Peter Otten
Michael Hoffman wrote: >> def list_members(obj) >>l = dir(obj) >>return map(lambda x : eval('obj.'+x), l) > > That works fine for me with Python 2.4. Python 2.4 (#6, Jan 30 2005, 11:14:08) [GCC 3.3.3 (SuSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >

Re: eval function not working how i want it dag namn

2005-04-15 Thread Peter Otten
robcarlton wrote: > hi everybody > I've written this function to make a list of all of an objects > attributes and methods (not for any reason, I'm just learning) > > def list_members(obj) > l = dir(obj) > return map(lambda x : eval('obj.'+x), l) > > but I get an error saying that obj is

Re: eval function not working how i want it dag namn

2005-04-15 Thread Gerald Klix
How about using the vars builtin? Michael Hoffman schrieb: robcarlton wrote: I've written this function to make a list of all of an objects attributes and methods (not for any reason, I'm just learning) def list_members(obj) l = dir(obj) return map(lambda x : eval('obj.'+x), l) That works

Re: eval function not working how i want it dag namn

2005-04-15 Thread Michael Hoffman
robcarlton wrote: I've written this function to make a list of all of an objects attributes and methods (not for any reason, I'm just learning) def list_members(obj) l = dir(obj) return map(lambda x : eval('obj.'+x), l) That works fine for me with Python 2.4. This is the best way to do it:

eval function not working how i want it dag namn

2005-04-15 Thread robcarlton
hi everybody I've written this function to make a list of all of an objects attributes and methods (not for any reason, I'm just learning) def list_members(obj) l = dir(obj) return map(lambda x : eval('obj.'+x), l) but I get an error saying that obj isn't defined. As I understand it eval