Software Engineering Code Library-Python

Source: Internet
Author: User
This is mainly because I don't want to let myself get old and find the old code I have previously written. it is both laborious and easy to get bored. So we can put the summary here. This is mainly because I don't want to let myself get old and find the old code I have previously written. it is both laborious and easy to get bored. So we can put the summary here.

Parse string into time object and calculate the interval (in seconds)

# Calculate the difference between the two timestamps import timefrom datetime import datetimefmt = "% Y-% m-% dT % H: % M: % S. % fZ "#2016-02-18T12: 22: 22.123456Ztime1 _ obj = datetime. strptime (time1, fmt) time2_obj = datetime. strptime (time2, fmt) time_interval = int (time. mktime (time2_obj.timetuple ()-time. mktime (timestamps obj.timetuple ()))

Call shell command in Python script

# The combination of Python and Shell is useful in practical research. import subprocesssubprocess. call (["ls", "-l"], cwd = ".")

Read xml from file_path

import xml.etree.ElementTree as ETtree = ET.parse("test.xml")root = tree.getroot()# apply dom operations on root

For more articles about Python, see PHP!

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.