- Jython - Dialogs
- Jython - Menus
- Jython - Event Handling
- Jython - Layout Management
- Jython - Using the Swing GUI library
- Jython - JDBC
- Jython - Servlets
- Jython - NetBeans Plugin & Project
- Jython - A Project in Eclipse
- Jython - Eclipse Plugin
- Jython - Java Application
- Jython - Package
- Jython - Modules
- Jython - Functions
- Jython - Loops
- Jython - Decision Control
- Jython - Using Java Collection Types
- Jython - Variables and Data Types
- Jython - Importing Java Libraries
- Jython - Installation
- Jython - Overview
- Jython - Home
Jython Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Jython - Modules
A module is a Jython script in which one or more related functions, classes or variables are defined. This allows a logical organization of the Jython code. The Program elements defined in a module can be used in another Jython script by importing either the module or the specific element (function/class) from it.
In the following code (hello.py) a function SayHello() is defined.
#definition of function defSayHello(str): print "Hello ", str return
To use the SayHello() function from another script, import the hello.py module in it.
import hello hello.SayHello("TutorialsPoint")
However, this will import all functions defined in the module. In order to import specific function from module use following syntax.
from modname import name1[, name2[,... nameN]
For example, to import only the SayHello() function, change the above script as follows.
from hello import SayHello SayHello("TutorialsPoint")
There is no need to prefix the name of the module while calpng the function.
Advertisements