Software Engineering Idiom Code Library -- Python

高洛峰
Release: 2017-02-17 11:13:07
Original
1483 people have browsed it

The main reason I write this is because I don’t want to keep looking for the old code I wrote before, which is both tiring and tiring, and can easily make people bored. So I’ll summarize them all here.

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

# 计算两个时间戳的差值import timefrom datetime import datetime

fmt = "%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()))
Copy after login

call shell command in Python script

# Python 和 Shell 的结合在实际科研很有用
import subprocess
subprocess.call(["ls", "-l"], cwd=".")
Copy after login

read xml from file_path

import xml.etree.El
ementTree as ETtree = ET.parse("test.xml")
root = tree.getroot()
# apply dom operations on root
Copy after login

For more software engineering custom code libraries - Python related articles, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!