Python 3.x study notes 7 (module), python3.x

Source: Internet
Author: User
Tags timedelta

Python 3.x study notes 7 (module), python3.x

1. Definition:
Module: Used to logically organize python code (variables, functions, classes, and logic: implement a function). The essence is the python file ending with. py.
Package: Used to logically organize modules. In essence, a directory (must contain a _ init _. py file)

2. Import Method
Import module_name1, module_name2

From module import * (not recommended)

From module import m1, m2, m3
From module import m1 as m

3. import Essence
The essence of the import module is to explain the python file again.
The essence of the imported package is to execute the _ init _. py file under the package.

4. Import Optimization
From module_test import test

5. Module Classification
A. Standard Library
B. Open Source Module
C. Custom Module

Standard Library:
1. time and datetime

Strftime ("format", struct_time) -----> "formatted string"
Strptime ("formatted string", "format ")

6. Module Overview

Http://blog.51cto.com/egon09/p2

 

7. Example

Import timeprint (time. time () # returns the current timestamp print (time. altzone) # returns the time difference from utc time, in seconds-32400 print (time. asctime () # return time format: "Fri Jan 26 20:38:48 2018", print (time. gmtime () # The gmtime () method is to convert a timestamp to struct_time of the UTC time zone (0 time zone ).
Print (time. mktime (time. localtime () # convert a struct_time to a timestamp
Print (time. asctime () # present a time tuples or struct_time in this form: 'fri Jan 26 20:38:48 123 '. If no parameter exists, time. localtime () is passed in as the parameter.

Print (time. asctime (time. gmtime () # present a time tuples or struct_time in this form: 'fri Jan 26 20:38:48 123 '. If no parameter exists, time. localtime () is passed in as the parameter.


Print (time. ctime () # converts a timestamp (floating point number calculated by second) into time. asctime () format. If the parameter is not provided or is None, the default time. time () is used as the parameter. It is equivalent to time. asctime (time. localtime (secs )).

String_2_struct = time. strptime ("20:38:48", "% Y-% m-% d % H: % M: % S") # convert the date string to the format of the struct time object print (string_2_struct) print (time. gmtime (time. time ()-98546) # convert the utc timestamp to the print _time format print (time. strftime ("% Y-% m-% d % H: % M: % S", time. localtime () # convert utc struct_time format to the specified string format import datetimeprint (datetime. datetime. now () print (datetime. date. fromtimestamp (time. time () # The timestamp is directly converted to the date format 2011-1-26print (datetime. datetime. now () + datetime. timedelta (6) # current time + 6 days print (datetime. datetime. now ()-datetime. timedelta (6) # current time-6 days print (datetime. datetime. now () + datetime. timedelta (hours = 6) # current time + 6 hours print (datetime. datetime. now () + datetime. timedelta (minutes = 30) # current time + 30 minutes c_time = datetime. datetime. now () print (c_time.replace (minute = 3, hour = 2) # Replace time

 

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.