Python Learning notes-Package

Source: Internet
Author: User

Packages are used to merge a set of modules into a directory, which is a package, and the directory name is the package name


1. The package is a hierarchical file directory structure that defines a Python application execution environment consisting of modules and sub-packages

2. Based on the package, Python can specify the module's import path when executing the module import

Import directory name. Directory name. Module name

Import Dir1. Dir2. mod1


example, the conditions for building the package:

See if/opt/python361 is in the search path

In []: sys.pathout[28]: [',...... '/root/.ipython ', '/opt/python361 ']


Create a new folder under this directory Pkg1

[Email protected] python361]# ls__pycache__ mymod.py[[email protected] python361]# mkdir PKG1

A minimum of 2 files should be included in the PKG1 directory:

__init__.py (__init__.py can contain Python code, but is usually empty, used only to act as hooks for package initialization, to generate module namespaces for directories, and to implement the from * behavior when using catalog import)

        mod1.py (a module file)

[[Email protected] python361]# CD Pkg1/[[email protected] pkg1]# touch __init__.py[[email protected]kurol pkg1]# cd-/opt/ Python361[[email protected] python361]# ls__pycache__ mymod.py pkg1[[email protected] python361]# cp mymod.py pkg1/[[E Mail protected] python361]# CD Pkg1/[[email protected] pkg1]# ls__init__.py __pycache__ mymod.py[[email protected] pkg1] # MV Mymod.py mymmm.py


To import a package:

in [[]: Import Pkg1.mymmmin [34]:


This article is from the "Shei" blog, make sure to keep this source http://kurolz.blog.51cto.com/11433546/1935029

Python Learning notes-Package

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.