【发布时间】:2020-11-02 18:54:20
【问题描述】:
我正在尝试打开一个文件,使用re 找到一个模式,然后将模式的每个实例传递给一个函数进行处理,然后替换文件中的每个模式实例。我有一个工作函数。
from datetime import datetime
from time import time
def replacetimestamp(replace):
#document uses milliseconds not seconds.
x = replace * .001
dt_object = datetime.fromtimestamp(x)
return dt_object
print(dt_object)
一切都很好,所以当我尝试在我的主脚本中使用该函数时,我遇到了问题。我想要么我破坏了re 对象,要么我没有写入文件,但我尝试的一切都不起作用。
这是其余的:
import re
import time, datetime
import replacetimestamp
timestamp = re.compile(r'/d{13}')
for line in open("testpython.json"):
for timestamp in re.finditer(timestamp, line):
timestamp.replacetimestamp()
【问题讨论】:
-
python 3.9版
标签: json python-3.x string python-re