<jupyter_start><jupyter_text>---     Department of Data ScienceCourse: Tools and Techniques for Data Science---Instructor: <NAME>, Ph.D.     Lecture 2.15 (Part - II)  _mypackage.ipynb_  1- What are Python Packages?    2- How to Create a Python Package? **Let us create a package:**- First of all, remember a package is a directory and the name of the package is the name of the directory. - We create our directory with the name "_packageDemo_". - Inside this we create sub-directories "_package1_" and "_package2_".- The packageDemo, package1, and package2 directory needs to contain a file with the name '_ _ init _ _.py'. To keep things simple, we left these file empty.- Now we can put all of the Python files which will be the modules into these directory. We create 3 different modules named arithmetic, comparison and bitcompare, containing our function definitions.- We put arithmetic module in package1(sub-package), and place the comparison and bitcompare module in package2 (sub-package) Hierarchy: - **packageDemo**     - `__init__.py`      - **package1**             - `___init__.py`             - `arithmetic.py`           - **package2**             - `__init__.py`         - `comparison.py`         - `bitcompare.py`  packageDemo/package1/arithmetic.py```def myadd(a,b):    return a+bdef mysub(a,b):    return a-bdef mymul(a,b):    return a*bdef mydiv(a,b):    if (y==0):        return 'Not Possible'    else:        return a/bdef mypow(a,b):    return a**b```  pakcageDemo/package2/bitcompare.py```def bitand(a,b):    print('a & b is',a&b)    def bitor(a,b):    print('a | b is',a|b)def bitnot(a):    print('~a is',~a)def bitxor(a,b):    print('a ^ b is',a^b)def bitright(a,b):    print('x >> b is',a>>b)def bitleft(a,b):    print('a << b is',a<<b)```  pakcageDemo/package2/comparison.py```def comparison(x,y):    print("Comparing both operand where x is ",x,"and y is ",y)        if(x>y):        print(" x > y is: ",  x>y)            elif(x<y):        print(" x < y is: ", x<y)            else:        print(" x == y is: ", x==y)    ```  3. How to import and use modules from the Package **Using functions inside the arithmetic module**<jupyter_code>import packageDemo.package1.arithmetic
packageDemo.package1.arithmetic.mymul(12, 15)
import packageDemo.package1.arithmetic as abc
abc.mypow(2,10)
from packageDemo.package1 import arithmetic
arithmetic.myadd(5,3)
from packageDemo.package1.arithmetic import *
myadd(3,9)
print(dir())<jupyter_output>['In', 'Out', '_', '_2', '_4', '_6', '_8', '__', '___', '__builtin__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', '_dh', '_i', '_i1', '_i2', '_i3', '_i4', '_i5', '_i6', '_i7', '_i8', '_i9', '_ih', '_ii', '_iii', '_oh', 'abc', 'arithmetic', 'exit', 'get_ipython', 'myadd', 'mydiv', 'mymul', 'mypow', 'mysub', 'packageDemo', 'quit']<jupyter_text>**Using functions inside the comparison module** **Using functions inside the bitcompare module** **Using functions of all the modules**<jupyter_code>from packageDemo.package1 import arithmetic as arith
from packageDemo.package2 import bitcompare as bits
from packageDemo.package2 import comparison as comp<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14864864864864866, 'fraction_numerical': 0.016027655562539284, 'mean_word_length': 3.989028213166144, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '584702', 'license': 'BSL-1.0', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1020, 'n_words': 337, 'path': 'data-science-master/Section-2-Basics-of-Python-Programming/Lec-2.15-Creating-Python-Modules-and-Packages/package-files/mypackage.ipynb', 'repo_name': 'Hamid-Ali-99/Python_Just_Python', 'size': '3194'}