gpt4 book ai didi

python - 我如何在django中找到临时文件的路径

转载 作者:太空狗 更新时间:2023-10-29 20:38:10 25 4
gpt4 key购买 nike

我正在这样使用 pdftk

pdftk template.pdf fill_form /temp/input.fdf 输出 /temp/output .pdf

现在一切正常

但是现在我已经用这个生成了临时文件而不是/temp/input.fdf

myfile = tempfile.NamedTemporaryFile()
myfile.write(fdf)
myfile.seek(0)
myfile.close()

现在我不知道如何将我的文件作为输入传递给 pdftk

最佳答案

myfile.name 将为您提供文件路径。

请注意,close() 之后不存在 tempfile。来自文档:

 tempfile.TemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, 
prefix='tmp'[, dir=None]]]]])

Return a file-like object that can be used as a temporary storage area. The file is created using mkstemp(). It will be destroyed as soon as it is closed (including an implicit close when the object is garbage collected). Under Unix, the directory entry for the file is removed immediately after the file is created. Other platforms do not support this; your code should not rely on a temporary file created using this function having or not having a visible name in the file system.

来源:http://docs.python.org/2/library/tempfile.html

关于python - 我如何在django中找到临时文件的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13717314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com