Вы можете использовать re
для получения желаемых номеров. Для второй ошибки используйте звездочку *
, чтобы распаковать кортеж:
import re
from datetime import date
txt = r'''PARTIALRUN,0
time,2020-07-31 12:21:44
update,5.8.6.32
build,2319
comments,testing
BaseDir,\\Testing\Python\2020_07_31_12_21_44'''
t = re.search(r'time,([^\s]+)', txt).group(1)
t = tuple(map(int, t.split('-')))
u = re.search(r'update,(.*)', txt).group(1)
b = re.search(r'build,(.*)', txt).group(1)
print('WeekNumber= {}'.format(date(*t).isocalendar()[1]))
print('{}NUMBER{}'.format(u, b))
Выводит:
WeekNumber= 31
5.8.6.32NUMBER2319
EDIT: (для чтения из файла):
import re
from datetime import date
with open('file_location', 'r') as f_in:
txt = f_in.read()
t = re.search(r'time,([^\s]+)', txt).group(1)
t = tuple(map(int, t.split('-')))
u = re.search(r'update,(.*)', txt).group(1)
b = re.search(r'build,(.*)', txt).group(1)
print('WeekNumber= {}'.format(date(*t).isocalendar()[1]))
print('{}NUMBER{}'.format(u, b))