style(4-1): 替换 f-string 为 format 方法- 将 f-string 替换为 str.format 方法,以适应 Python 3.6 以下版本- 修改了三处 print 语句和一处变量赋值,使用 str.format 方法替代 f-string

This commit is contained in:
fly6516 2025-04-20 02:29:25 +08:00
parent 250e1b99e0
commit e84c0ff633

6
4-1.py
View File

@ -114,13 +114,13 @@ def parse_goldfile_line(goldfile_line):
GOLDFILE_PATTERN = '^(.+),(.+)'
match = re.search(GOLDFILE_PATTERN, goldfile_line)
if match is None:
print(f'Invalid goldfile line: {goldfile_line}')
print('Invalid goldfile line: {0}'.format(goldfile_line))
return (goldfile_line, -1)
elif match.group(1) == '"idAmazon"':
print(f'Header datafile line: {goldfile_line}')
print('Header datafile line: {0}'.format(goldfile_line))
return (goldfile_line, 0)
else:
key = f'{match.group(1)} {match.group(2)}'
key = '{0} {1}'.format(match.group(1), match.group(2))
return ((key, 'gold'), 1)
# 9. 使用广播变量提高效率