1

我正在 Python 3.8.5 中编写一个脚本,用户需要输入一个字符串,guid在我的数据库中调用,TinyDB 将打印回filename相同上传的值,但我终生无法弄清楚如何打印密钥,filename以便os.remove可以删除具有匹配文件名的文件。我已经尝试过如何从 TinyDB 数据库中检索单个值的解决方案?但我无法让它在我的代码中工作。

数据库:

{
"_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"])

谢谢。

4

0 回答 0