Re: [Jython-users] TypeError: too many arguments
by Kent Johnson other posts by this author
Nov 25 2004 12:53PM messages near this date
[Jython-users] how to create interfaces in jython
|
Re: [Jython-users] Multiple PythonInterpreter objects and Java threads
What does your Jython implementation of IJavaInterface look like? My
guess is that you left off the 'self' argument to login(); i.e. in you
.py file you should have something like this:
import IJavaInterface
class MyInterface(IJavaInterface):
def login(self):
pass
Member functions should always have at least one argument - self. If you
omit the 'self' argument that will cause the error you are getting.
Kent
Stephane Blardone wrote:
>
>
> Im trying to use an instance of a java interface ( the interface is
> implemented in jython) in a java program.
>
>
>
> Using the __tojava__ method I get a java instance of the jython object
> but when I try to call a method of the
>
> interface from java I get a TypeError: login() too many arguments;
> expected 0 got 1
>
>
>
> heres the code I use.
>
>
>
> IJavaInterface myJythonObject = null;
>
>
>
> PythonInterpreter tInterp = new PythonInterpreter();
>
> Properties tPythonProperties = new Properties();
>
> tPythonProperties.setProperty("python.path", c:/share/lib" );
>
> PythonInterpreter.initialize(System.getProperties(),
> tPythonProperties, null);
>
>
>
> try {
>
>
>
> File tFile = new File("c:/temp/test.py ");
>
> FileInputStream tFileStream = new FileInputStream(tFile);
>
> try {
>
>
>
> tInterp.setErr(System.out);
>
> tInterp.execfile(tFileStream);
>
> tInterp.exec("x=TestClass()");
>
> PyObject pObj1 = tInterp.get("x");
>
> myJythonObject =
> (IjavaInterface)pObj1.__tojava__( IjavaInterface.class);
>
>
>
> myJythonObject.login(); ß-------this throws a
> TypeError: too many arguments
>
> }
>
> catch(Exception tEx) {
>
> System.out.println(tEx.toString());
>
> }
>
> }
>
>
>
> I have looked at previous postings on jython-user and googled the
> problem but I have not found a solution
>
> Im a jython newb so I probably either missed something or made some
> incorrect assumptions.
>
> Should I not be using the myJythonObject like it is a java object?
>
> I can use __findattr__(login) and use the __call__ method but this
> would defeat the purpose of the interface.
>
>
>
> Any help would be greatly appreciated.
>
>
>
> -stephane
>
>
>
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/
_______________________________________________
Jython-users mailing list
Jython-users@[...].net
https://lists.sourceforge.net/lists/listinfo/jython-users
|