这是我的示例代码:importosfromtempfileimportmkstempfname=mkstemp(suffix='.txt',text=True)[1]os.remove(fname)当我在我的Linux上运行它时,它工作正常。但是当我使用Python3.4.4在我的WindowsXP上运行它时,它引发了以下错误:Traceback(mostrecentcalllast):File"C:\1.py",line5,inos.remove(fname)PermissionError:[WinError32]Theprocesscannotaccessthefilebecaus
以下哪项更正确?fi,path=tempfile.mkstemp()f=os.fdopen(fi,"w")f.write(res)f.close()os.close(fi)或:fi,path=tempfile.mkstemp()f=os.fdopen(fi,"w")f.write(res)f.close() 最佳答案 查看f.fileno(),应该和fi一样。您应该只关闭该文件描述符一次,所以第二次是正确的。在Unix上,第一个会导致错误:>>>f.close()>>>os.close(fi)Traceback(mostrecent
在我的机器上,Linux机器ulimit-n给出1024。这段代码:fromtempfileimportmkstempforninxrange(1024+1):f,path=mkstemp()在最后一行循环失败:Traceback(mostrecentcalllast):File"utest.py",line4,inFile"/usr/lib/python2.7/tempfile.py",line300,inmkstempFile"/usr/lib/python2.7/tempfile.py",line235,in_mkstemp_innerOSError:[Errno24]Tooma
已结束。此问题不符合StackOverflowguidelines.它目前不接受答案。这个问题似乎与aspecificprogrammingproblem,asoftwarealgorithm,orsoftwaretoolsprimarilyusedbyprogrammers无关.如果您认为该问题将成为anotherStackExchangesite上的主题,您可以发表评论,说明在哪里可以回答问题。关闭去年。Improvethisquestion我有以下设置来定期将文件从服务器Arsync到服务器B。服务器B的rsync守护程序使用以下配置运行:readonly=falseusechr