Python Modules

In Python, a module is simply a file with the .py extension that contains Python code.  Python modules are imported into other Python modules using the import or from keywords. Importing modules makes the objects in those modules accessible to the module doing the import.

Example

Let's say you have a file called "moduleToImport.py" that looks like this:

Python
class ImportedClass():
    def sayHello(self):
        print('hello')

the module name is "moduleToImport" which can be used like this:

Python
import moduleToImport
myImportedClass = moduleToImport.ImportedClass()
myImportedClass.sayHello()

Output

Hello