我可以在文件夹中搜索所有版本日志行,但我试图在列表中选择最新版本,但我不知道如何选择,因为列表的元素同时包含字符和数字。
下面是我的代码,用于查找和创建一个名为matched_lines 的列表,其中包含说明日志版本号的所有行。我希望从这个创建的列表中找到最新版本,并将这个最新版本与日志之外的实际最新版本进行比较。例如,生成的列表将包括:
['版本 2.13.1.1'、'版本 2.12.1.0'、'版本 2.10.1.4']
在本例中,我希望选择“版本 2.13.1.1”,并将其与日志的最新版本号进行比较,例如“版本 2.14.1.0”。
for filename in files:
#print('start parsing... ' + str(datetime.datetime.now()))
matched_line = []
try:
with open(filename, 'r', encoding = 'utf-8') as f:
f = f.readlines()
except:
with open(filename, 'r') as f:
f = f.readlines()
# print('Finished parsing... ' + str(datetime.datetime.now()))
for line in f:
#0strip out \x00 from read content, in case it's encoded differently
line = line.replace('\x00', '')
#regular expressions to fidn the version log lines for each type
RE1 …Run Code Online (Sandbox Code Playgroud)