Re: Perl vs. Python question...

2009-07-14 Thread Lloyd Kvam
On Tue, 2009-07-14 at 15:32 -0400, Joshua Judson Rosen wrote: > > The simplistic self.foo = self.compute_foo() will trigger a call to > > __getattr__, so you can't use that within __getattr__. > > That's not true; it *will*, however, trigger a call to __settattr__, > if it exists; that's what you'

Re: Perl vs. Python question...

2009-07-14 Thread Joshua Judson Rosen
Lloyd Kvam writes: > > On Mon, 2009-07-13 at 22:59 -0400, Paul Lussier wrote: > > Lloyd Kvam writes: > > > > > You've already gotten two useful responses. I'd just like to add that > > > typically, the object attributes are referenced directly: > > > rect.length * rect.width > > > > Ll

Re: Perl vs. Python question...

2009-07-14 Thread Paul Lussier
Lloyd Kvam writes: > If the value will be computed on demand, __getattr__ is one way to go. > def __getattr__(self, attr): > if attr == 'foo': > return self.compute_foo() > elif > else: > raise AttributeError( attr +

Re: Perl vs. Python question...

2009-07-14 Thread Lloyd Kvam
On Mon, 2009-07-13 at 22:59 -0400, Paul Lussier wrote: > Lloyd Kvam writes: > > > You've already gotten two useful responses. I'd just like to add that > > typically, the object attributes are referenced directly: > > rect.length * rect.width > > Lloyd, thanks. But what if the attribute

Re: Perl vs. Python question...

2009-07-13 Thread Paul Lussier
Lloyd Kvam writes: > You've already gotten two useful responses. I'd just like to add that > typically, the object attributes are referenced directly: > rect.length * rect.width Lloyd, thanks. But what if the attribute isn't set yet? If I have self.foo, and self.foo hasn't yet been set

Re: Perl vs. Python question...

2009-07-13 Thread Bill McGonigle
On 07/11/2009 11:44 PM, Paul Lussier wrote: > In perl, I can use the AUTOLOAD feature to dynamically create methods, > something like this: It looks like in perl6 you get this for free. I'm just getting started with it though. -Bill -- Bill McGonigle, Owner Work: 603.448.4440 BFC Com

Re: Perl vs. Python question...

2009-07-13 Thread Lloyd Kvam
On Sat, 2009-07-11 at 23:44 -0400, Paul Lussier wrote: > How do I create dynamically created methods in python classes? > > For example, if I have a number of member variables which I want to > get > or set, I don't want to have to create getters and setters for each > attribute, since the code wo

Re: Perl vs. Python question...

2009-07-12 Thread Steven W. Orr
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 07/11/09 23:44, quoth Paul Lussier: > Hi Folks, > > How do I create dynamically created methods in python classes? > > For example, if I have a number of member variables which I want to get > or set, I don't want to have to create getters and set

Re: Perl vs. Python question...

2009-07-12 Thread Joshua Judson Rosen
Paul Lussier writes: > > Hi Folks, > > How do I create dynamically created methods in python classes? > > For example, if I have a number of member variables which I want to get > or set, I don't want to have to create getters and setters for each > attribute, since the code would largely be the

Perl vs. Python question...

2009-07-11 Thread Paul Lussier
Hi Folks, How do I create dynamically created methods in python classes? For example, if I have a number of member variables which I want to get or set, I don't want to have to create getters and setters for each attribute, since the code would largely be the same, just the variable I'm dealing