Re: Wrapper objects

2004-12-11 Thread Bengt Richter
On 10 Dec 2004 15:03:01 -0800, [EMAIL PROTECTED] wrote: >>Well, that could be a feature, depending on what your use case is. >>Or you could make a method for adding methods, I suppose. >>A perfectly transparent wrap of obj would be to do nothing ;-) >>What do you actually want to do? > >Actually,

Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
[EMAIL PROTECTED] wrote: The wrapper objects needs to work as dictionary keys, to support printing, concatenation/addition, getitem/setitem and such things... In that case, identifying exactly which operations you want to support, and using a metaclass based approach like mine or Bengt's should wo

Re: Wrapper objects

2004-12-10 Thread redhog
>Well, that could be a feature, depending on what your use case is. >Or you could make a method for adding methods, I suppose. >A perfectly transparent wrap of obj would be to do nothing ;-) >What do you actually want to do? Actually, the very best would if only type(), isinstance() and the is-key

Re: Wrapper objects

2004-12-10 Thread redhog
As to what I want to use this for, I today have a huge program in which several objects are wrapped up with comments (made up by some DOMish structre) which are displayed to the user at various times. For example, a list of users may be represented as as comment "List of users" and a python list of

Re: Wrapper objects

2004-12-10 Thread redhog
Ah, thanks. I didn't think of the possibility of creating a list of methods that needed wrapping, and wrapping them uppon creation of the wrapper object. Mainly I think, becaus it seems to me as such an uggly workaround for a misdesign in Python. Also, if the wrapped object gets some extra methods/

Re: Wrapper objects

2004-12-10 Thread Bengt Richter
On 10 Dec 2004 09:33:51 -0800, [EMAIL PROTECTED] wrote: >Bengt Richter wrote: >> On 9 Dec 2004 06:11:41 -0800, [EMAIL PROTECTED] (Egil M?ller) wrote: >> >> >So my naive implementation of a wrapper class, >> > >> > >> >class wrapper(object): >> >def __init__(self, value, otherdata): >> >

Re: Wrapper objects

2004-12-10 Thread redhog
Bengt Richter wrote: > On 9 Dec 2004 06:11:41 -0800, [EMAIL PROTECTED] (Egil M?ller) wrote: > > >Is there any way to create transparent wrapper objects in Python? > > > >I thought implementing __getattribute__ on either the wrapper class or > >its metaclass would do the trick, but it does not work

Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
Kent Johnson wrote: Nick Coghlan wrote: Simon Brunning wrote: This work - ? Only for old-style classes, though. If you inherit from object or another builtin, that recipe fails. Could you explain, please? I thought __getattr__ worke

Re: Wrapper objects

2004-12-10 Thread Kent Johnson
Nick Coghlan wrote: Simon Brunning wrote: This work - ? Only for old-style classes, though. If you inherit from object or another builtin, that recipe fails. Could you explain, please? I thought __getattr__ worked the same with new-

Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
Simon Brunning wrote: On 9 Dec 2004 06:11:41 -0800, Egil M?ller <[EMAIL PROTECTED]> wrote: Is there any way to create transparent wrapper objects in Python? This work - ? Only for old-style classes, though. If you inherit from object o

Re: Wrapper objects

2004-12-09 Thread Bengt Richter
On 9 Dec 2004 06:11:41 -0800, [EMAIL PROTECTED] (Egil M?ller) wrote: >Is there any way to create transparent wrapper objects in Python? > >I thought implementing __getattribute__ on either the wrapper class or >its metaclass would do the trick, but it does not work for the built >in operators: > >

Re: Wrapper objects

2004-12-09 Thread Simon Brunning
On 9 Dec 2004 06:11:41 -0800, Egil M?ller <[EMAIL PROTECTED]> wrote: > Is there any way to create transparent wrapper objects in Python? This work - ? -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -