Re: properties vs. eval()

2005-05-07 Thread Jason Mobarak
Bob Rogers wrote: > So you're saying you don't know the answer? The question wasn't > "should I use setattr?" If what you're doing is wrong and backwards then it doesn't matter what the question is. Best practices are best practices for a reason. There's no reason to use eval to do what you want

Re: properties vs. eval()

2005-05-06 Thread Steve Holden
Bob Rogers wrote: > So you're saying you don't know the answer? The question wasn't > "should I use setattr?" > No, the "*question*" was (paraphrasing slightly) "is [it] possible to dispense with the compile step and use eval() alone while setting a property" the *answer* was "you should use se

Re: properties vs. eval()

2005-05-05 Thread Bob Rogers
So you're saying you don't know the answer? The question wasn't "should I use setattr?" -- http://mail.python.org/mailman/listinfo/python-list

Re: properties vs. eval()

2005-05-05 Thread Jason Mobarak
Why are you using eval in the first place? This isn't bash. Use setattr and getattr for dynamic attribute access. -- http://mail.python.org/mailman/listinfo/python-list

Re: properties vs. eval()

2005-05-04 Thread Michael Hoffman
Peter Otten wrote: > Use > > eval(s) > > to evaluate an expression and > > exec s > > to execute a statement. I never thought of using compile() to get around this before. Now I can finally use print in my lambda functions! Just think of the horrible code I could write: f = lambda x: ev

Re: properties vs. eval()

2005-05-04 Thread Peter Otten
Bob Rogers wrote: > Given this class: > > class C(object): > def set_x(self, x): > self._x = x > > def get_x(self): > return self._x > > x = property(get_x, set_x) > > > This use of compile() and eval() works as I expected it to: > > c = C() > c.x = 5000

properties vs. eval()

2005-05-04 Thread Bob Rogers
Given this class: class C(object): def set_x(self, x): self._x = x def get_x(self): return self._x x = property(get_x, set_x) This use of compile() and eval() works as I expected it to: c = C() c.x = 5000 n = '\'five thousand\'' code = compile('c.x