Software engineering Idioms code base--Python article

Source: Internet
Author: User
If you don't want to be old enough to find old code that you've written before, it's exhausting and labor, and it's easy to get bored. So the summary is put on this side of the good.

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

# Calculates the difference of 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 (Time1_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

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.