Python Common libraries

Source: Internet
Author: User

A. Standard library, time datetime two standard library
1.time and datetime 1) timestamp 2) format time 3) Ganso (struct_time) Total nine elements, time.localtime () tuple data

UTC GMT China utc+8 eight hours earlier than standard time


Time () get timestamp
Gmtime () Time to convert time to UTC time zone
LocalTime () The current timestamp is converted to a tuple. or the meta-group information of the time stamp passed in

Time stamp
Timestamp to tuple gmtime (time)-to UTC time zone
LocalTime (Time)--current TimeZone

Tuple to timestamp mktime (time) to convert tuples to timestamps


Convert tuples to formatted string strftime ('%y-%m-%d ', (tuple time))
Convert time format to meta-ancestor strptime ("2017-07-16", "Time format") returns a time tuple

Asctime (accepts tuple data) CTime (time stamp is passed in)


Datetime.datetime.now () Gets the current time with Datetime.timedelta (3) using the current time corresponding to the 3 day-+3 or hours=3
Calculate the first three days or three hours before, three years, etc.


B Random floating-point standard library



C OS Module
OS.GETCWD () Gets the current working directory,
Os.chdir ("CC") changes the current script working directory

D SYS system module
Pring (SYS.ARGV 1234) Get parameters

E shutil File Operation module

F JSON pickle Module
JSON primarily serializes the conversion between user strings and Python data types
Dumps dump loads load
Pickle function dumps dump loads load Python-specific modules
G shelve module, simple kv memory data through the file persistence module, you can persist any pickle can support the Python data format


H XML Processing Module
Import Xml.etree.ElementTree as ET introduces XML processing module

Python Common libraries

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.