Problems in Packages
1. To Write a program to import the
package named matplotlib.
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.
from [Link] import plot
print(plot)
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.
import [Link] as mat
print(dir(mat)[:3])
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/[Link] File: [Link]
def getName1(): from [Link] import getName1
print("ModuleA") from [Link] import getName2
File: mypackage/[Link] 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/[Link]
File: [Link]
def getName1():
print("[Link]") from [Link] import getName1
File: transport/roads/[Link] from [Link] import getName2
getName1()
getName2()
def getName2():
print("[Link]")
Thank you