Modules

Python Modules helps us to access or manage code in multiple files. Creating a module is just like we create libraries in Python.

To understand module, let’s create two python files in the same folder and try to access first file variables and functions in to second file.

Please place below code in both the files:

person.py

in person.py file we have created one name variable outside of address class at line number 1.

In the same person.py file, created one more variable as firstName and method as printFirstName() within in the address class.

main.py

Write an import person statement in main.py file or module for accessing variables and functions from person module.

Note: Please read comment while going through code will help you to understand code better.

OUTPUT:

Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.

0