Packages
Python Packages
Suppose you have developed a very large application that includes many modules. As the number of modules grows, it becomes difficult to keep track of them all if they are dumped into one location. This is particularly so if they have similar names or functionality. You might wish for a means of grouping and organizing them.
Packages allow for a hierarchical structuring of the module namespace using dot notation. In the same way that modules help avoid collisions between global variable names, packages help avoid collisions between module names.
We will create a new package. Go to our project, new and choose Python package, it will automatically creat the _ini_ file
We will call it marketing
If a file named
__init__.py
is present in a package directory, it is invoked when the package or a module in the package is imported. This can be used for execution of package initialization code, such as initialization of package-level data.
From that package, we will create a Module so right click in our project, go to'new 'and go to 'New file'
We're adding in this module a function to calculate the whole sales
Now we would like to import the global_sale module into the prueba3 package
We can import the whole module or we can select some functions or classes only
1.- Importing the whole module
2.- Importing the specific function, we use the "from" statement and delete "Sales dept".
Packages
Reviewed by ohhhvictor
on
May 13, 2019
Rating:
No comments: