|
|
|
@ -0,0 +1,39 @@
|
|
|
|
|
# calculate.py 文件
|
|
|
|
|
import time # 导入时间模块,用于控制计算频率 [3](@ref)
|
|
|
|
|
import csv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(a, w1):
|
|
|
|
|
try:
|
|
|
|
|
x = 1
|
|
|
|
|
while True:
|
|
|
|
|
y = int(a)+x # 将输入字符串转换为整数并计算 [3](@ref)
|
|
|
|
|
w1.insert(1.0, str(y)+'\n') # 在文本区域插入计算结果 [3](@ref)
|
|
|
|
|
time.sleep(1) # 暂停1秒,控制刷新频率 [3](@ref)
|
|
|
|
|
x += 1
|
|
|
|
|
except Exception:
|
|
|
|
|
w1.insert(1.0, '请输入数字\n') # 捕获异常并提示用户 [3](@ref)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def query_isbn(isbn, csv_path='datas/books.csv'):
|
|
|
|
|
"""
|
|
|
|
|
同步查询ISBN信息(直接返回结果)
|
|
|
|
|
|
|
|
|
|
:param isbn: ISBN编号(字符串)
|
|
|
|
|
:param csv_path: CSV文件路径(默认当前目录)
|
|
|
|
|
:return: 匹配记录字典或错误信息字符串
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
with open(csv_path, 'r', encoding='utf-8') as f:
|
|
|
|
|
reader = csv.DictReader(f)
|
|
|
|
|
for row in reader:
|
|
|
|
|
if row['isbn'].strip() == isbn.strip(): # 增加空格过滤
|
|
|
|
|
return row
|
|
|
|
|
return "未找到匹配的图书记录"
|
|
|
|
|
except FileNotFoundError:
|
|
|
|
|
return f"错误:文件 {csv_path} 不存在"
|
|
|
|
|
except Exception as e:
|
|
|
|
|
return f"查询失败:{str(e)}"
|