我试图通过.csv文件(我在Excel中打开)进行搜索并在字段中查找特定数字。我正在搜索的号码来自GUI中的用户输入。如果在该字段中找到该号码,则将输出同一行中的其他字段中的所有项目。这是该文件的内容: screen shot of the file in excel 问题是,我似乎无法创建一段可以通过.csv读取并查找编号的代码。 这是我到目前为止(这只是不工作的代码部分):在CSV中搜索项目
def search(): # defining the function
term=str(e3.get()) # getting the user input and setting it to the varible 'term'
import csv # from all my researching, this is required to open the file
open('Book1.csv') # opens the file
# the code to look through the file would be here. It must search for the number in the correct field and output an error if it can't find it
print() #this will print the data in the same row as the number from the different fields for the user
如果你有一个解决方案,请给我的代码,将尽正是我需要它去做。如果你解释了它做了什么,我将不胜感激,但如果你不这样做并不重要。感谢您提前回复。
欢迎来到SO。所以你想要一个答案,但不关心,如果没有解释?你没有兴趣学习后来自己使用它们的功能吗? –
_“给我的代码将完成我所需要的”_堆栈溢出不是一个真正的“免费代码写入服务”,更多的是一个学习的地方。可能想看看[游览]。 – ashleedawg
对不起,这两个人说我错误地使用了网站,但是当我连续编写了将近12个小时而没有运气的时候,我非常渴望得到答案。我将铭记未来。 – Matthew64