![]() ![]() Now, if we run the test.py module, we will get the exact output as above. We know that the _init_.py file is not mandatory for 3.x versions of python, so let us remove that file from the packe1 folder and execute this program again. Step6 : Run test.py module in the command prompt and the output is: Step5 : create a test.py module and import module1 functionality function1() from pack1.module1 import function1 Step4 : If you open a pack1 folder, you can see two files inside it. Print("This is an F1 function present in module1 of pack1 package") Step3 : Now, create one more file with the below code and save inside the pack1 folder as module1.py def function1(): Step2 : And, this pack1 folder should contain two files such as _init_.py and module1.py, so goto python IDLE and select a new file and save an empty file in the pack1 folder. Step1 : I am going to create a pack1 folder in my current working directory called python codes ![]() So you are going to learn how to create a package and how to define modules inside a package and also learn how to access package-module functionality from test.py. The following example demonstrates the use of python packagesĬonsider my working contains a module called test.py and this module contains some packages and within that packages, and this pack contains a file _init_.py and module1.py file and inside this module1.py I want to define a function, and I want to access these function from test.py module. Maintainability of the application will be improved.The readability of the application will be improved.Improves the Modularity of the application.We can identify our components uniquely.Naming conflicts can be solved easily.Python provides some of the advantages of using python packages: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |