Jython Tutorial
Jython Useful Resources
Selected Reading
- 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 - Package
Jython - Package
Any folder containing one or more Jython modules is recognized as a package. However, it must have a special file called __init__.py, which provides the index of functions to be used.
Let us now understand, how to create and import package.
Step 1 − Create a folder called package1, then create and save the following g modules in it.
#fact.py def factorial(n): f = 1 for x in range(1,n+1): f = f*x return f
#sum.py def add(x,y): s = x+y return s
#mult.py def multiply(x,y): s = x*y return s
Step 2 − In the package1 folder create and save the __init__.py file with the following content.
#__init__.py from fact import factorial from sum import add from mult import multiply
Step 3 − Create the following Jython script outside the package1 folder as test.py.
# Import your Package. import package1 f = package1.factorial(5) print "factorial = ",f s = package1.add(10,20) print "addition = ",s m = package1.multiply(10,20) print "multippcation = ",m
Step 4 − Execute test.py from Jython prompt. The following output will be obtained.
factorial = 120 addition = 30 multippcation = 200Advertisements