要比较QLineEdit()和CSV文件的值,你可以使用以下解决方法:
import csv
from PyQt5.QtWidgets import QLineEdit
# 读取CSV文件并存储值到列表中
csv_values = []
with open('file.csv', 'r') as file:
csv_reader = csv.reader(file)
for row in csv_reader:
csv_values.append(row[0]) # 假设CSV文件只有一列数据
# 获取QLineEdit()的值
line_edit_value = QLineEdit().text()
# 比较CSV文件的值和QLineEdit()的值
if line_edit_value in csv_values:
print("QLineEdit()的值存在于CSV文件中。")
else:
print("QLineEdit()的值不存在于CSV文件中。")
import csv
from PyQt5.QtWidgets import QLineEdit
# 获取QLineEdit()的值
line_edit_value = QLineEdit().text()
# 逐行比较CSV文件的值和QLineEdit()的值
with open('file.csv', 'r') as file:
csv_reader = csv.reader(file)
for row in csv_reader:
if line_edit_value == row[0]: # 假设CSV文件只有一列数据
print("QLineEdit()的值存在于CSV文件中。")
break
else:
print("QLineEdit()的值不存在于CSV文件中。")
确保替换file.csv
为你的CSV文件路径,并将代码插入到适当的位置以与你的其他代码进行交互。