The tutorial will introduce you to Python Packages. This Python basic tutorial will help you understand creating a Python package. You will understand the example of a Python Package. After that, you will understand different ways to access Python Packages. Further, the demonstration will educate you on how to create Python Package.
2. Creating a Python Package
Example of a Python
Package
Different ways to access
Python Packages
What are Python Packages?
What’s in it for you?
3. What are Python Packages?
Packages are the same as a directory containing other
sub-packages and modules in a structured way, making
the sub-packages and modules easy to access
This is an analogy to a folder, as folders allow us to
store files. Packages help us keep other sub-packages
and modules to be used by the user when necessary
4. Creating a Python Package
__init__.py
• The directory that contains the __init__.py file is
defined as a Python package
• A package can be imported the same way as a
module is imported
• A Package must contain a special file with
name __init__.py
• __init__.py file can be empty
5. Example of a Python Package
Package
Music Application
__init__.py
Playlist filter
__init__.py
singer.py
genre.py
album.py
Sub-package
options
__init__.py
speed.py
repeat.py
shuffle.py
Sub-package
Play
__init__.py
start.py
next.py
previous.py
Sub-package
Signup.py
6. Different ways to access Python Packages
You can use different Syntax to import Packages in Python
Syntax: import packageName.moduleName
Syntax: import packageName.subPackageName.moduleName
Syntax: from packageName import moduleName
Syntax: from packageName.subPackageName import moduleName
Syntax: from packageName import *
Syntax: from packageName.moduleName import func_name
7. INDIA
Simplilearn Solutions Pvt. Limited
#53/1C, 24th Main, 2nd Sector
HSR Layout, Bangalore 560102
Phone: +91 8069999471
UNITED STATES
Simplilearn Solutions Pvt. Limited
801 Corporate Center Drive, Suite 138
Raleigh, NC 27607
Phone: (919) 205-5565
UNITED STATES
Simplilearn Solutions Pvt. Limited
201 Spear Street, Suite 1100
San Francisco, CA 94105
Phone: (415) 741-3319
Join us to learn more!