FYI:
Found a good answer at the python mailing list... Satisfies my needs...
If anyone is interested:
class Delegator(object):
def __init__(self, delegate):
self.delegate = delegate
def __getattr__(self, attr):
return getattr(self.delegate, attr)
Example:
>>> a=Delegator([])
>>> a.append(5)
>>> a.delegate
[5]
-----Original Message-----
From: Noam Aigerman [mailto:noama@...]
Sent: Wednesday, February 11, 2009 1:29 AM
To: Alan Kennedy; jython-users@...
Subject: Re: [Jython-users] Wrapper for java instances
Thanks, But it won't help - the thing is I am using a java library which
has a lot of methods that return a java object of type X. Upon receiving
that object, I want to enclose some more data in it, thus I want to be
able to add attributes dynamically. I can't subclass it since that won't
help me as I don't create the object but rather get it *after* it
already exists. So I can't really see any other way out of it but a
wrapper...
I am sure there is some way to propagate function calls from the wrapper
object to the internal object (without defining explicitly that
wrapper.x() calls __internal.x() for each method of __internal)...
Thanks, noam
-----Original Message-----
From: Alan Kennedy [mailto:jython-dev@...]
Sent: Wednesday, February 11, 2009 1:13 AM
To: jython-users@...
Subject: Re: [Jython-users] Wrapper for java instances
[Noam]
> Suppose I have a java object:
> Import java.awt
> w=java.awt.Window()
>
> now, I would really like to use it as a python object, i.e do things
like
> adding attributes on the fly like
>
> w.ddddddd=2
>
> Which jython doesn't allow me, I'm guessing becaue w is a java object
and
> not a python object (BTW - I don't really use a Window instance in the
real
> code). Is there a way around it, or am I not using jython correctly?
Try subclassing the java class with a jython class, like so.
class JavaAwtWindow(java.awt.Window): pass
w = JavaAwtWindow()
w.ddddddd=2
HTH,
Alan.
------------------------------------------------------------------------
------
Create and Deploy Rich Internet Apps outside the browser with
Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and
code to
build responsive, highly engaging applications that combine the power of
local
resources and data with the reach of the web. Download the Adobe AIR SDK
and
Ajax docs to start building applications
today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users
------------------------------------------------------------------------
------
Create and Deploy Rich Internet Apps outside the browser with
Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and
code to
build responsive, highly engaging applications that combine the power of
local
resources and data with the reach of the web. Download the Adobe AIR SDK
and
Ajax docs to start building applications
today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Jython-users mailing list
Jython-users@...
https://lists.sourceforge.net/lists/listinfo/jython-users
|