How to Create Python Modules

A Python module is a file that contains function definitions and statements. You can import a module into your current Python project and access all of its functions. You can even create your own Python module and fill it with your favorite function definitions. This allows you to reuse your code without copying and pasting it into all your source code files. Any Python script that is saved to a file with a Python extension is a module.

Instructions

    • 1

      Click on the IDLE text editor icon that came bundled with the Python language. The text editor loads a blank source code file.

    • 2

      Click on "File" at the top of the page and select "Save As" from the menu that expands.

    • 3

      Write a name for your module and make sure the file type is ".py," which is the default option.

    • 4

      Click on the Save button to save the file as a module. This module is empty, but you can add any function definitions and statements you want to it. Once you have filled your module with custom definitions, you can import it into another Python project by typing the following at the top of the source code file (replace "module-name" with the file name of your module):

      import module-name

Related Searches:

References

Resources

Comments

You May Also Like

Related Ads

Featured