The fifth day of the Python devops development

Source: Internet
Author: User
Tags greenwich time zone

One, the module five most

Definition, importing method, import essence (path Search), import optimization, module classification

1. Definition:

Modules are used to logically organize Python code (variables, functions, classes, logic to implement a function), which is essentially the. Py end of the Python file

2. How to Import

(1) Import module_name1,module_name2

Import multiple words, separated by ","

(2) from Module_alex Import * (Import all functions inside the module, not recommended)

or from Module_alex import m1,m2,m3

(3) from Module_alex import logger as Logger_alex

Alias mechanism, imported module logger from the individual name Logger_alex, reference logger_alex.xxx

3. Import Essence

(1) Interpret all Module_alex code once, assign to Module_alex (All_Code), use module_alex.xxx when calling

(2) from ... import name

Directly open the name variable in the Module_alex file, get the current explanation and execute it again, calling name directly

Summary: The essence of the import module is to interpret the Python file again

(3) Python package: The essence is a directory (must contain the __init__.py file), logically organize the module

The essence of the import package is to interpret the __init__.py file under the Execute Package

Process: Search Module--Find module--Explain execution

Search for the environment variable defined by Sys.path (), find it and not go back.

4. Import optimization

From module_test Import test

If the method is used too much, it is recommended to use the method above

5, the classification of the module

Standard library (built-in module), open source module, custom module

Second, built-in modules

(1) Time and datetime

A, time stamp

B. Formatted time string

C, tuple (struct_time) a total of nine elements

Method: Time.time () timestamp

Time.clock

Time.sleep () Sleep for a few seconds

Time.gmtime () Convert Narimoto Group (Greenwich time Zone)

Time.localtime () turn into tuples (local area)

Time.mktime () tuple converted to timestamp

Time.strftime () tuples converted into words

Time.strptime () string to tuple (note one by one correspondence)

Asctime () tuple to string (specific format)

CTime () timestamp to string (same format as above)

The fifth day of the Python devops development

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.