Modules and Packages

Make you share code between scripts.
Make you able to import a module ( file with a code )

Example :
import file_ex  ( file_ex.py )
dir(file_ex)
then you would be able to use all method and attribute of that module.
file_ex.”attribute“(‘passing element needed‘)

To understand how python look for its information when importing data :
import sys
from pprint import pprint
pprint(sys.path)

when importing anything, python will start looking in the 1st location and then going down the tree.

You can be more specific when importing functions:
From file_ex import “attribute

The difference between the 2 is when calling it :
import function = you need to use : function.”attribute”(‘element’) 
from ‘function’ import ‘attribute_from_function’ = you can call directly : “attribute“.(‘element‘)

Once the module is imported you can call the different keys of as an example a dictionary :
from module import key or keys, keys, etc…

 

Leave a Comment