Calling Jython code from Java

Discussion in 'Python' started by Raja, May 18, 2004.

  1. Raja

    Raja Guest

    I have a java class thats trying to call something in python. This
    works fine when i do a jythonc on the python script.
    When i call another python script from the __init__ of my called
    python script, things go bad.i get this message
    AttributeError: class 'configuration' has no attribute
    'configuration'
    when calling the constructor.
    This is my python script thats called by the java class
    testconfig.py
    =============
    import configuration
    import java.lang

    class testconfig(java.lang.Object):

    def __init__(self):
    """@sig public testconfig()"""
    self._cfg = configuration.configuration("/sources/jmxproto")

    def getValue(self, whatVar):
    pass

    and the other script is configuration.py
    class configuration:

    def __init__(self, runtimeDir=None):
    """@sig public configuration(java.lang.String dir)"""
    """ Some code in here """

    When i call testconfig.py, i get the error mentioned above. Any clues?

    Thanks
    Raja
    Raja, May 18, 2004
    #1
    1. Advertising

  2. Raja wrote:
    > I have a java class thats trying to call something in python. This
    > works fine when i do a jythonc on the python script.


    [snip]

    >
    > class testconfig(java.lang.Object):
    >
    > def __init__(self):
    > """@sig public testconfig()"""
    > self._cfg = configuration.configuration("/sources/jmxproto")


    [snip]

    > class configuration:
    >
    > def __init__(self, runtimeDir=None):
    > """@sig public configuration(java.lang.String dir)"""
    > """ Some code in here """
    >
    > When i call testconfig.py, i get the error mentioned above. Any clues?


    In Python, you just use the class name to create instances.

    So I think that perhaps:

    self._cfg = configuration.configuration("/sources/jmxproto")

    Should be:

    self._cfg = configuration("/sources/jmxproto")

    IIRC the "@sig" declaration only comes into play when attempting to use
    the class from *Java* code. That's why there is no "configuration"
    attribute.

    Regards,
    Derek.
    Derek Thomson, May 18, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GP
    Replies:
    1
    Views:
    930
    andreas kinell
    Oct 17, 2004
  2. David McNab
    Replies:
    0
    Views:
    453
    David McNab
    Apr 9, 2004
  3. Divya Prakash
    Replies:
    0
    Views:
    425
    Divya Prakash
    Dec 19, 2006
  4. Pinegar, Kent T

    FW: [Jython-users] Jython Licensing Question

    Pinegar, Kent T, Jul 24, 2008, in forum: Python
    Replies:
    0
    Views:
    343
    Pinegar, Kent T
    Jul 24, 2008
  5. potchi
    Replies:
    0
    Views:
    413
    potchi
    May 18, 2011
Loading...

Share This Page