Python module,

Source: Internet
Author: User

Python module,
Introduction:

Module: a collection of code that implements a function. There are three types:

  • Custom Module
  • Third-party module
  • Built-in modules
Python to find the module path

Where, the third-party module installation location

Tip: The third-party module name cannot be the same as the built-in or third-party module name.

Import module: from lib. account import login

 

Add the sys. path:

 

OS module (related to the system)

OS. stat ("path") to get the file directory information

OS. path. dirname (path) Get the directory where the file is located

OS. path. exists (path) If path exists, true is returned; otherwise, false is returned.

OS. path. join (path1 [, path2 [,...]) returns the results after combining multiple paths. The parameters before the first absolute path are ignored.

 

Hashlib module: (encryption-related operations)

User name. The password must be encrypted

Md5 encryption cannot be reversed.

Because the md5 data on each computer is the same, the user name and password corresponding to the encryption will be obtained by others. Therefore, you must customize the data so that the data encrypted by md5 only exists on your computer.

Encrypted login registration instance:

 

 

 

Built-in modules

_ Doc _ is the comment of the py file

_ File _ # file path

_ Package _ under which folder the current py file is located, if multiple paths are connected.

_ Cached _ used for caching

_ Name _ (important)

_ Name _ = '_ main:

Main file: Before calling a function, add _ name _ = '_ main __'

 

Json serialization (Json is a string)

Json. loads is used to convert the list, dictionary, and tuples into corresponding dictionaries, lists, and tuples (note the error message and format)

The format of the note. An error is returned.

Json. dumps () converts the obtained dictionary, list, And tuples into corresponding strings.

Json. dump () Get the content and write it into the corresponding file.

 

Configparser module: (open and read files in specific formats) (default files are strings)

 

 

 

Shutil module (Advanced file, folder, and compressed Package Processing Module)

 

Subprocess Module

 

Logging module (important) (used to easily record logs and ensure thread security)

 

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.