Re: Wrapping classes with pure virtual functions

2006-12-17 Thread Roman Yakovenko
On 14 Dec 2006 13:57:10 -0800, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote: Hi, I'm having problems wrapping a hierarchy of classes, actually having problems wrapping the base class. I don't need to use the WrapClass mechanism since I don't want to override classes in Python. My code boils down

Re: Wrapping classes with pure virtual functions

2006-12-17 Thread Carl Banks
[EMAIL PROTECTED] wrote: > Chris Lambacher wrote: > > On Thu, Dec 14, 2006 at 01:57:10PM -0800, [EMAIL PROTECTED] wrote: > > > Hi, > > > I'm having problems wrapping a hierarchy of classes, actually having > > > problems wrapping the base class. I don't need to use the WrapClass > > > mechanism sin

Re: Wrapping classes with pure virtual functions

2006-12-17 Thread [EMAIL PROTECTED]
Chris Lambacher wrote: > On Thu, Dec 14, 2006 at 01:57:10PM -0800, [EMAIL PROTECTED] wrote: > > Hi, > > I'm having problems wrapping a hierarchy of classes, actually having > > problems wrapping the base class. I don't need to use the WrapClass > > mechanism since I don't want to override classes

Re: Wrapping classes with pure virtual functions

2006-12-17 Thread Chris Lambacher
On Thu, Dec 14, 2006 at 01:57:10PM -0800, [EMAIL PROTECTED] wrote: > Hi, > I'm having problems wrapping a hierarchy of classes, actually having > problems wrapping the base class. I don't need to use the WrapClass > mechanism since I don't want to override classes in Python. My code > boils down to

Re: Wrapping classes

2005-09-23 Thread Michael Spencer
Jeremy Sanders wrote: > Colin J. Williams wrote: > > >>Could you not have functions a and b each of which returns a NumArray >>instance? >> >>Your expression would then be something like a(..)+2*b(..). > > > The user enters the expression (yes - I'm aware of the possible security > issues), as

Re: Wrapping classes

2005-09-23 Thread Pedro Werneck
I agree this is a case for using metaclasses. What about an implementation like this ? Seems like checking if init was already called will slow down all attribute access significantly, but, I don't like this approach of changing the __init__ method. class LazyInit(type): def __new__(self, n

Re: Wrapping classes

2005-09-23 Thread Jeremy Sanders
Colin J. Williams wrote: > Could you not have functions a and b each of which returns a NumArray > instance? > > Your expression would then be something like a(..)+2*b(..). The user enters the expression (yes - I'm aware of the possible security issues), as it is a scientific application. I don'

Re: Wrapping classes

2005-09-23 Thread Colin J. Williams
Jeremy Sanders wrote: > Peter Hansen wrote: > > >>Almost anything is possible in Python, though whether the underlying >>design idea is sound is a completely different question. (Translation: >>try the following pseudo-code, but I have my suspicions about whether >>what you're doing is a good i

Re: Wrapping classes

2005-09-23 Thread Jeremy Sanders
bruno modulix wrote: > Could it work with a UserDict subclass ? Unfortunately not: Traceback (most recent call last): File "test.py", line 17, in ? print eval("10 * a + b", globals(), l) TypeError: eval() argument 3 must be dict, not instance Thanks Jeremy -- Jeremy Sanders http://www.

Re: Wrapping classes

2005-09-23 Thread bruno modulix
Jeremy Sanders wrote: > Diez B. Roggisch wrote: > > >>It works - in python 2.4!! I tried subclassing dict, but my >>__getitem__-method wasn't called - most probably because it's a C-type, >>but I don't know for sure. Maybe someone can elaborate on that? > > > Yes - I tried that (see thread belo

Re: Wrapping classes

2005-09-23 Thread Jeremy Sanders
Diez B. Roggisch wrote: > It works - in python 2.4!! I tried subclassing dict, but my > __getitem__-method wasn't called - most probably because it's a C-type, > but I don't know for sure. Maybe someone can elaborate on that? Yes - I tried that (see thread below). Unfortunately it needs Python 2.

Re: Wrapping classes

2005-09-23 Thread Diez B. Roggisch
Jeremy Sanders wrote: > Peter Hansen wrote: > > >>Almost anything is possible in Python, though whether the underlying >>design idea is sound is a completely different question. (Translation: >>try the following pseudo-code, but I have my suspicions about whether >>what you're doing is a good i

Re: Wrapping classes

2005-09-23 Thread Jeremy Sanders
Peter Hansen wrote: > Almost anything is possible in Python, though whether the underlying > design idea is sound is a completely different question. (Translation: > try the following pseudo-code, but I have my suspicions about whether > what you're doing is a good idea. :-) ) What I'd like to

Re: Wrapping classes

2005-09-23 Thread Paolino
Paolino wrote: > class NotInitializedObjects(type): > def __init__(cls,*_): > realInit=cls.__init__ > def __newInit__(self,*pos,**key): > def _init(): > realInit(self,*pos,**key) > self._init=_init > cls.__init__=__newInit__ > def __getattribute__(self,attr):

Re: Wrapping classes

2005-09-23 Thread bruno modulix
Jeremy Sanders wrote: > Is it possible to implement some sort of "lazy" creation of objects only > when the object is used, but behaving in the same way as the object? Smells like a Proxy pattern... > For instance: > > class Foo: > def __init__(self, val): > """This is really slow.""" >

Re: Wrapping classes

2005-09-23 Thread Paolino
Jeremy Sanders wrote: > Is it possible to implement some sort of "lazy" creation of objects only > when the object is used, but behaving in the same way as the object? > A generic approach would override __getattribute__ to let it perform the __init__ method on not initialized objects.This is a

Re: Wrapping classes

2005-09-22 Thread Peter Hansen
Jeremy Sanders wrote: > Is it possible to implement some sort of "lazy" creation of objects only > when the object is used, but behaving in the same way as the object? > > For instance: > > class Foo: > def __init__(self, val): > """This is really slow.""" > self.num = val > > # this d