我正在开发一个从 .txt 文件中读取数字并使用正则表达式搜索它的程序,因此如果我将 20.00 放入 .txt 文件中,我想使用正则表达式在我的抓取列表中查找 20.00。
问题是当我将 .txt 文件中的正则表达式读入列表时,我不知道如何让正则表达式读取它。
.txt 有类似的东西
姓名 = 鲍勃
付款 = 20.00
payline = control_txt.readline().split(' ')
control_txt.readline()
payAmount = payline[2]
我有额外的 readline b/c 我的 txt 文件有由 enter 分隔的行
name = my_lst[0]
regAmount = re.compile(payAmount)
amount = list(filter(regAmount.match, msg_lst))
if amount:
print(name + ' ' + '$' + amount[0])
我希望最终输出看起来像 bob $20.00
如果我使用类似 ('20.00') 的东西,它会起作用,但我需要它是一个变量而不是硬编码数字。
当我尝试做
payAmount = ("'" + payline[2] + "'")
它打印为
'20.00
'
慕村9548890
相关分类