KnowledgeBoat Logo

Computer Science

Create a package from above two modules as this :

Conversion  
    ├──Length   
    │   └──Lengthconversion.py   
    └──Mass  
        └──Massconversion. py  

Make sure that above package meets the requirements of being a Python package. Also, you should be able to import above package and/or its modules using import command.

Python Libraries

2 Likes

Answer

  1. The basic structure of above package includes packages's name i.e., Conversion and all modules and subfolders.
  2. Create the directory structure having folders with names of package and subpackages. In the above package, we created two folders by names Length and Mass. Inside these folders, we created Lengthconversion.py and MassConversion.py modules respectively.
  3. Create __init__.py files in package and subpackage folders. We created an empty file and saved it as "__init__.py" and then copy this empty __init__.py file to the package and subpackage folders.
  4. Associate it with python installation. Once we have our package directory ready, we can associate it with Python by attaching it to Python's site-packages folder of current Python distribution in our computer.
  5. After copying our package folder in site-packages folder of our current Python installation, now it has become a Python library so that now we can import its modules and use its functions.

Directory structure is as follows:

Conversion/
    ├── __init__.py
    ├── Length/
    │     ├── __init__.py
    │     └── Lengthconversion.py
    └── Mass/
          ├── __init__.py
          └── MassConversion.py

Answered By

1 Like


Related Questions