Home > Articles > Programming > Java

Extending Jython

  • Print
  • + Share This
From the author of

__doc__ Strings

You can define a module's doc string by assigning a string to the __doc__ key in the dictionary passed to the classDictInit method as shown in Listing 1, or better yet, you can include a static PyString class member named __doc__ in the Java class:

public static __doc__ = new PyString("Some documentation");

The line above defines the module's doc string, but how do you define a function's doc string? The static methods within a Java class become module functions in Jython. In Listing 1, the static fibTest method behaves like the fibTest function within a Jython module. To add a doc string to this function means adding a static PyString called __doc__fibTest. Creating doc strings for other functions means following the same convention of assigning a static PyString to an identifier named __doc__functionName. Listing 1 uses this to assign documentation to the fibTest method than can be retrieved from Jython as mymod.fibTest.__doc__.

  • + Share This
  • 🔖 Save To Your Account