The difference between directory directories and package packages in the Getting Started Python pycharm

Source: Internet
Author: User

For Python, one thing to know is that Python is a relatively lightweight, easy-to-use scripting language (which is not limited to this, and is only discussed here), and as the program grows, you may want to divide it into several files so that logic is clearer, better maintained, Or you want to use a function in several programs without having to copy and paste it into all programs.

To support this, Python has a way to place definition functions in a file and use them in scripts, which are called modules, and definitions in a module can be imported into other modules, or in the main module.

In short, the module in Python refers to a py file, if we put all the relevant code in a py file, the py file is not only the program is the module, but the program and the module is designed to be different, the purpose of the program is to run, and the purpose of the module is for other programs to reference.

      • Dictionary

        Dictionary is a folder in Pycharm, where a resource file is placed, corresponding to the directory used to place the Css/js file during Javaweb development, or the folder used to store the background image when the object is recognized. This folder does not contain _ _ init.py_ _ File

      • Python Package

        For Python package folders, unlike dictionary, they automatically create _ init__.py files.
        Simply put, the Python package is a directory that includes a set of modules and a _ _ init__.py file.

        image/
        _init _.py
        jpg.py
        tiff.py
        bmp.py

As long as the image directory is a subdirectory of our program directory, we can import any module under the image directory for our use, as follows:

Import= Image.bmp.read ('a.bmp')

_ _ Init_ _.py

This file is related to the import mechanism of Python, which relates to which of your. py files are externally accessible. Sometimes, if there are many modules under a package, it is cumbersome and not elegant to import so many modules in the caller, at this point you can do this by modifying _ _ Init_ _.py.
Define the Special variable _ All_ in _ _ init_. py , and copy the module that will be included to the variable, for example, define all _=[' in image/_ init_ . py Tiff ', ' bmp ', ' jpg '], where all corresponds to the From ... import * refers to the module, at this time in the reference party using the following statement:

 from Import *= tiff.read ('a.tiff')

Add:

The Python module is:
Self-contained and organized code fragments for modules.
The representation is: the written code is saved as a file. This file is a module. sample.py where the file name Smaple is the module name.

Python packages are:
A package is a hierarchical file directory structure that defines a Python application execution environment consisting of n modules or N sub-packages.

Popular point: The package is a directory containing __init__.py files, which must have this __init__.py file and other modules or sub-packages.

The Python library is a reference to other programming languages, meaning a collection of code that accomplishes a certain function in Python, a combination of code that the user uses. In Python is the form of packages and modules.

Libraries are generally designed according to API conventions.
Application Interface (English:Application Programming Interface, abbreviation:API), also known as application programming interface is the agreement of the different components of the software system. Due to the increasing scale of software in recent years, it is often necessary to divide complex systems into small components, and the design of programming interfaces is very important. In the practice of program design, the programming interface is designed to make the responsibility of software system be divided rationally. Good interface design can reduce the mutual dependence of various parts of the system, improve the cohesion of the constituent units, reduce the coupling degree between the components, thus improving the maintainability and expansibility of the system.

Reference: https://www.cnblogs.com/LancyWu/p/7283889.html

Huanggo
Links: https://www.zhihu.com/question/30082392/answer/46698211

The difference between directory directories and package packages in the Getting Started Python pycharm

Related Article

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.