0% found this document useful (0 votes)
8 views7 pages

Python Package Import Examples

The document discusses problems with importing packages and modules in Python. It provides examples of importing from the matplotlib package, creating custom packages and modules, and creating sub-packages. The examples show how to import specific functions and modules from packages and sub-packages and call functions from the imported modules.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Python Package Import Examples

The document discusses problems with importing packages and modules in Python. It provides examples of importing from the matplotlib package, creating custom packages and modules, and creating sub-packages. The examples show how to import specific functions and modules from packages and sub-packages and call functions from the imported modules.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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

You might also like