Problems in Python Packages
Problems in Python Packages
import matplotlib
print(dir(matplotlib)[:3])
Output:
[‘AitoffAxes’, ‘Axes3D’, ‘HammerAxes’]
2. To write a program to import the function plot
from the module pyplot in the matplotlib package.
Output:
<function plot at 0x113167c10>
3. To write a program to import the sub-package projections
from the matplotlib package and alias it as mat.
Output:
[‘AitoffAxes’, ‘Axes3D’, ‘HammerAxes’]
4. To create a package mypackage with modules moduleA and
moduleB. Both modules must contain a function that prints a
string of that module name. Also create another python file to
run the two functions.
File: mypackage/moduleA.py File: main.py
def getName1(): from mypackage.moduleA import getName1
print("ModuleA") from mypackage.moduleB import getName2
File: mypackage/moduleB.py getName1()
def getName2(): getName2()
print("ModuleB")
Output
ModuleA
moduleB
5. To create a sub-package road with modules cars and bikes in the
package transport. Both modules must contain a function that prints a
string of that module name. Also create another python file to run the
two functions.
File: transport/roads/cars.py
File: main.py
def getName1():
print("Cars.py") from transport.road.cars import getName1
File: transport/roads/bikes.py from transport.road.bikes import getName2
getName1()
getName2()
def getName2():
print("Bikes.py")
Thank you