Chapter 3 Using Python Librarieseng
Chapter 3 Using Python Librarieseng
Python Libraries
This is module.
This is module.
Output
Module Aliasing in Python
• When you import member of any module with alia name then
you have to use the following syntax -
from <ModuleName> import <MemberName> as <AliaName>
This is module.
Output
PACKAGE / LIBRARY
• Python Package is the collection of same type of modules.
• You can use built in package as well as your own package.
• Python Package is a simple directory. Modules are stored in
that directory.
• Package or library are generally same.
• Steps to make a package is as follows – (geometry)
1. We create a folder (directory) named geometry which will contain
two files area.py and volume.py
2. In the same directory we will put another file named “__init__.py”
3. __init__.py is necessary because this is the file which tells Python
that directory is package. And this file initializes the package
4. Then we import the package and use the content.
Making PACKAGE / LIBRARY
This is the folder
which will be our
package.
Output
Locating The Module
• When we import a module then interpreter of
python searches the module in the following
sequence –
1. First current directory
2. If module not found then it will be searched in
shell variable PYTHONPAT.
3. If not found anywhere then python searches in
default. Default path is the path where Python
is installed.
Standard Python Libraries
• In last chapter we discussed about math and string
module. Same way we will discuss two more
important libraries. - datetime library या datetime
module.
• Python supports yyyy-mm-dd format for date. It has
tow important classes -