Send Close Add comments: (status displays here)
Got it!  This site "robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.  Note: This appears on each machine/browser from which this site is accessed.
Module examples
by RS  admin@robinsnyder.com : 1024 x 640


1. Module examples
This page contains some examples of module examples in various programming languages.

2. Module
A module is a piece of code that contains data and code to be shared and used by other code, as in a library.

3. Module examples
Some issues arise in most language systems.

4. Naming modules
It helps to have a standard naming practice for modules and namespaces. One way is to use the initials of the company. I tend to use my initials "rms" or "rs" as a prefix. This lets me know that this is one of my modules instead of some other module.

Some systems support hierarchical name spaces.

5. Modules in Python
A Python module is a Python code file that acts as a name space.

The Python code file is included using the import statement.

6. Python module
Here is a code module in Python [module rmsTest in rmsTest.py].


7. Python module remarks
The Python module is in a file called rmsTest.py. This file should be in the Python path. I normally put all of my Python files in one folder that is in that path.

8. Python program
Here is the Python code [#2]

Here is the output of the Python code.


9. Python program remarks
The import statement is used to import a module.

The import as statement can be used to import a module but with a different name.

The from import can be used to import names that then do not need the module prefix. Or asterisk "*" can be used to import all module routines.


10. End of page

by RS  admin@robinsnyder.com : 1024 x 640