gpt4 book ai didi

python - 名称错误 : name 'book' is not defined

转载 作者:行者123 更新时间:2023-12-01 05:59:14 25 4
gpt4 key购买 nike

这是我的代码:

#!/usr/bin/python 

from xml.etree.ElementTree import ElementTree
from array import *
#import re

count = array('i',[0,0,0])

def find_root_tags(file,str1,i):

tree = ElementTree()
tree.parse(file)
root = tree.getroot()
if root == str1:
count[i] = count[i]+1

for j in tree.getiterator(str1):
count[i] = count[i] + 1

print "%dth file's count %d" % (i,count[i])


str1 = input("enter the word to be searched:")
fo = open("xml.txt","r")

for i in range(count.__len__()):

file = fo.readline()
find_root_tags(file,str1,i)

fo.close()

运行代码时出现此错误:

enter the word to be searched:book

Traceback (most recent call last):

File "keywords.py", line 23, in <module>

str1 = input("enter the word to be searched\n")

File "<string>", line 1, in <module>

NameError: name 'book' is not defined

为什么?

最佳答案

input() 的作用类似于 Python 2 的 eval(raw_input()):

input(...)
input([prompt]) -> value

Equivalent to eval(raw_input(prompt)).

您可能正在寻找raw_input()

关于python - 名称错误 : name 'book' is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11280194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com