问题描述
我正在用Python 3.8.5编写脚本,用户需要在我的数据库中输入一个名为guid
的字符串,TinyDB将为相同的上载打印回filename
的值,但是我一辈子都想不出如何仅打印filename
键,以便os.remove
可以删除具有匹配文件名的文件。我已经在How to retrieve a single value from a TinyDB database?上尝试过该解决方案,但无法在我的代码中使用它。
数据库:
{
"_default": {
"11": {
"upload_time": "17/Aug/2020 13:39:30","uploader_ip": "127.0.0.1","guid": "ORcjzt96PB3jQ7xtytxe","token": "test_123","filename": "RPADeQ.txt","filetype": "application/x-www-form-urlencoded"
}
}
}
fileForDel = input("Input file's GUID: ")
print(log.search(file.guid == str(fileForDel)))
confirm = input("Delete this file? (y/n)")
log.remove(file.guid == fileForDel)
print("Deleted the file successfully!")
伪代码
output = log.search(file.guid == str(fileForDel))
os.remove(output["filename"])
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)