日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python如何打印时间,在python2.7中,如何提取和打印日期、时间和m

發(fā)布時(shí)間:2025/3/20 python 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python如何打印时间,在python2.7中,如何提取和打印日期、时间和m 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

代碼如下:#!/usr/bin/env python

#Import the datetime

from datetime import datetime

import re

#Create two datetime object for limit 1 and limit 2 as dt1 and dt2 respectively

dt1 = datetime.strptime("01:00:00","%H:%M:%S").time()

dt2 = datetime.strptime("04:59:59","%H:%M:%S").time()

#Create a compiler for regular expression

init_re = re.compile(r'(INIT)')

time_re = re.compile(r'(\d+:\d+:\d+)')

# read line from test.log file

for line in open("test.log", "r"):

match = time_re.search(line) #Search time format for each line

if match:

matchtime = match.group(1)

dt_match = datetime.strptime( matchtime, '%H:%M:%S').time()

#Time formmat match

if dt_match >= dt1 and dt_match <= dt2:

match1 = init_re.search(line) #search INIT format

if match1:

matchinit = match1.group(0)

print match.string.strip()

以下是日志文件的一部分:2015-12-15 00:51:01,904 INFO restser.py 113 [INIT] [netkv_restser: peek] [req_id: f0aa7ab5-6192-4231-93cd-82a53936a072] [request: {u'key_space': u'martech_user_index', u'table_name': u'nettopic', u'key': 9569}]

我想要這樣的輸出:

^{pr2}$

示例:[Date:2015-12-15 ] [Time:00:51:01,904 ] [INIT] [netkv_restser:peek ] [req_id:f0aa7ab5-6192-4231-93cd-82a53936a072 ]

注意:如果您有足夠的能力編輯代碼,請(qǐng)?zhí)峁┙鉀Q方案。我不想聽(tīng)上去粗魯無(wú)禮,但這讓我討厭。在

注意:我使用的是python2.7.6。在

總結(jié)

以上是生活随笔為你收集整理的python如何打印时间,在python2.7中,如何提取和打印日期、时间和m的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。