- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to write a python module?
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py
create helloworld.py then write the following function as its content:
def hello_world(): print "Hello world"
Now create another file in the same directory called script.py. Write the following as its contents:
import helloworld helloworld.hello_world()
We created the helloworld module and imported it in script.py. Then we used the function from helloworld.py. Creating many modules in the working directory can create a lot of clutter. You can use packages to neatly group multiple modules together. You can read about how packages are created and used in detail here: https://docs.python.org/2/tutorial/modules.html#packages
- How to develop a Python Module?
- How to install a Python Module?
- Read and Write to an excel file using Python openpyxl module
- How to locate a particular module in Python?
- How to retrieve Python module path?
- Create and write on excel file using xlsxwriter module in Python
- How to import a single function from a Python module?
- How to list all functions in a Python module?
- Import a module in Python
- How do I unload (reload) a Python module?
- How to prohibit a Python module from calling other modules?
- How to import a Python module given the full path?
- Python getpass Module
- How to write a recursive function in Python?
- How to call Python module from command line?