从NUM = re.search线
该代码创建这种类型的错误类型错误获取一个类型的错误“字符串”从NUM = re.search线
这里是代码
import re f=open('JokesPC.txt', 'w')
f.write('how does a king react when he farts?')
print("how does a king react when he farts?")
#answer is nothing noble gases don't cause reactions
answer = input("what is your answer?")
f.write(answer)
f.close()
f = open('JokesPC.txt', 'r')
count = 0
num = 0
for line in f:
num = re.search("?P<[G|g]host>")
for i in num:
count += 1
print(count)
f.close()
回答:
搜索需要2个参数,第一个是您想要搜索模式的模式和第二个字符串。因为你没有提供第二个参数,它提供了一个字符串来查找正则表达式模式,你会得到错误。因此,作为一个修复只需更换以下与
num = re.search("?P<[G|g]host>", line)
以上是 从NUM = re.search线 的全部内容, 来源链接: utcz.com/qa/261099.html