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
- The basic structure of above package includes packages's name i.e., Conversion and all modules and subfolders.
- 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.
- 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.
- 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.
- 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
What are the possible outcome(s) executed from the following code ? Also specify the maximum and minimum values that can be assigned to variable PICK.
import random PICK = random.randint(0, 3) CITY = ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"]; for I in CITY : for J in range(1, PICK): print(I, end = " ") print()
- DELHIDELHI
MUMBAIMUMBAI
CHENNAICHENNAI
KOLKATAKOLKATA - DELHI
DELHIMUMBAI
DELHIMUMBAICHENNAI - DELHI
MUMBAI
CHENNAI
KOLKATA - DELHI
MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA
- DELHIDELHI
Write a Python program having following functions :
- A function with the following signature :
remove_letter(sentence, letter)
This function should take a string and a letter (as a single-character string) as arguments, returning a copy of that string with every instance of the indicated letter removed. For example, remove_letter("Hello there!", "e") should return the string "Hllo thr!".
Try implementing it using<str>.split()
function. - Write a function to do the following :
Try implementing the capwords() functionality using other functions, i.e., split(), capitalize() and join(). Compare the result with the capwords() function's result.
- A function with the following signature :
Create a module lengthconversion.py that stores functions for various lengths conversion e.g.,
- miletokm() — to convert miles to kilometer
- kmtomile() — to convert kilometers to miles
- feettoinches()
- inchestofeet()
It should also store constant values such as value of (mile in kilometers and vice versa).
[1 mile = 1.609344 kilometer ; 1 feet = 12 inches]
Help() function should display proper information.
Create a module MassConversion.py that stores function for mass conversion e.g.,
1.kgtotonne() — to convert kg to tonnes- tonnetokg() — to convert tonne to kg
- kgtopound() — to convert kg to pound
- poundtokg() — to convert pound to kg
(Also store constants 1 kg = 0.001 tonne, 1 kg = 2.20462 pound)
Help( ) function should give proper information about the module.