軟體工程慣用程式碼庫 -- Python 篇

高洛峰
發布: 2017-02-17 11:13:07
原創
1484 人瀏覽過

寫這篇主要是不想讓自己老去找以前寫過的舊程式碼,既勞心又勞力,還容易讓人產生厭煩情緒。所以總結一下都放在這邊好了。

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()))
登入後複製

call shell command in Python in Python script

# Python 和 Shell 的结合在实际科研很有用
import subprocess
subprocess.call(["ls", "-l"], cwd=".")
登入後複製

read xml from file_pathread

call shell command in Python script

import xml.etree.El
ementTree as ETtree = ET.parse("test.xml")
root = tree.getroot()
# apply dom operations on root
登入後複製
read xml from file_pathread🎜call shell command in Python script🎜rrreee🎜read xml from file_pathread🎜call shell command in Python script🎜rrreee🎜read xml from file_pathread🎜reee。中文網! 🎜
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!