使用tempfile.NamedTemporaryFile()报错PermissionError: [Errno 13] Permission denied

当使用tempfile.NamedTemporaryFile()创建临时文件并尝试操作时,可能会遇到PermissionError。官方文档建议,若要保留文件并进行操作,需在创建时设置delete=False。
摘要由CSDN通过智能技术生成

有问题就先查一下官方文档,内容如下:

"""
 tempfile.NamedTemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None[, delete=True]]]]]])
This function operates exactly as TemporaryFile() does, except that the file is guaranteed to have a visible name in the file 
system (on Unix, the directory entry is not unlinked). That name can be retrieved from the name attribute of the returned file-like 
object. Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across 
platforms (it can be so used on Unix; it cannot on Windows NT or later). If delete is true (the default), the file is deleted as 
soon as it is closed.The returned object is always a file-like object whose file attribute is the underlying true file object. 
This file-like object can be used in a with stat
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值