我在文件夹 A 中有一个 db 文件目录。我的 python 代码从另一个地方运行。
当我运行以下代码时:
path = 'xxx' # path to file directory
filenames = os.listdir(path) # list the directory file names
#pprint.pprint(filenames) # print names
newest=max(filenames)
print newest # print most recent file name
# would like to open this file and write to it
data=shelve.open(newest, flag="w")
它一直工作到最后一行,然后我收到一条错误消息:need "n" or "c" flag to run new db
.
如果没有最后一行的标志,例如:data=shelve.open(newest)
,文件名到达 Python 代码的目录,而 db 中没有任何数据。
我需要能够将最新返回的文件名放在“”中,但不知道如何。