jjzjj

tempFile

全部标签

python - 如何在 Python 中创建 tmp 文件?

我有这个引用文件路径的函数:some_obj.file_name(FILE_PATH)其中FILE_PATH是文件路径的字符串,即H:/path/FILE_NAME.ext我想在我的python脚本中创建一个文件FILE_NAME.ext,其中包含字符串的内容:some_string='thisissomecontent'如何解决这个问题?Python脚本将被放置在Linux盒子中。 最佳答案 我认为您正在寻找tempfile.NamedTemporaryFile.importtempfilewithtempfile.NamedTe

python - 如何创建一个临时目录并获取其路径/文件名?

如何在Python中创建临时目录并获取其路径/文件名? 最佳答案 使用mkdtemp()来自tempfile的函数模块:importtempfileimportshutildirpath=tempfile.mkdtemp()#...dostuffwithdirpathshutil.rmtree(dirpath) 关于python-如何创建一个临时目录并获取其路径/文件名?,我们在StackOverflow上找到一个类似的问题: https://stackove

python - 如何创建一个临时目录并获取其路径/文件名?

如何在Python中创建临时目录并获取其路径/文件名? 最佳答案 使用mkdtemp()来自tempfile的函数模块:importtempfileimportshutildirpath=tempfile.mkdtemp()#...dostuffwithdirpathshutil.rmtree(dirpath) 关于python-如何创建一个临时目录并获取其路径/文件名?,我们在StackOverflow上找到一个类似的问题: https://stackove

ruby-on-rails - 从新写入的 TempFile 中读取数据不起作用? Ruby on Rails 中的 IOerror 关闭流

我在RubyonRails中实现,我有2个View。在我的第一个View中,我读入了一个文件并显示了第一行(这很好用),然后在我的第二个View中(在Controller的方法中)我写了一个临时文件。一样。我想再次显示这个临时文件的内容。但这不起作用,我总是收到错误消息:IOErrorinProjectimporterController#resultclosedstream这是我在Controller中的代码,在我做的第一个View后面:tmpfile=Tempfile.new("tempfile")iftmpfiletmpfile.write(@samples)tmpfile.cl

python - 无法访问使用 tempfile 创建的临时文件

我正在使用tempfile.NamedTemporaryFile()存储一些文本直到程序结束。在Unix上工作没有任何问题,但在Windows上返回的文件无法读取或写入:python给出Errno13。唯一的方法是设置delete=False并使用os.remove()手动删除文件.为什么? 最佳答案 ThiscausestheIOErrorbecausethefilecanbeopenedonlyonceafteritiscreated.原因是因为NamedTemporaryFile在Windows上创建了带有FILE_SHARE

mysql表修复失败: "Can' t create new tempfile"

我经营一个WordPress网站。今天我发现wp_posts表崩溃了。当我尝试修复表时,出现以下错误:REPAIRTABLEwp_posts;errorCan'tcreatenewtempfile:'./[databasename]/wp_posts.TMD'repairstatusOperationfailed我尝试在shell中运行以下命令:myisamchk-r-fwp_posts.MYIerror:File'wp_posts.MYI'doesn'texist你能告诉我我还能尝试什么来解决这个问题吗? 最佳答案 原来“myis

python - 使用 tempfile 写入一个 csv 临时文件

所以我正在为这个类写一个测试(编辑得更清楚):classSpreadSheet(object):'''awesomedocstring'''def__init__(self,filename):self.filename=filenameself.table=[]self.headers=[]withopen(self.filename)ascsvfile:filereader=reader(csvfile,delimiter=',')forrowinfilereader:self.table.append(row)defcreate_headers(self,populations)

python - 如何在 Google App Engine 上的 django 中避免 NotImplementedError "Only tempfile.TemporaryFile is available for use"?

我通过use_library在GoogleAppEngine上使用Django1.1。这里没有使用DjangoGAEhelper、Djangonon-rel或类似工具。Django处理URL路由、表单验证等,但我使用的是纯AppEngine模型。在我的一个Django表单中有一个FileField,它有时似乎调用django.core.files.uploadedfile.TemporaryUploadedFile。此类随后使用tempfile.NamedTemporaryFile,这导致AppEngine提升:File"/base/python_runtime/python_dist

Python:tempfile.mkdtemp 和 tempfile.TemporaryDirectory 之间的区别

我需要创建一个临时目录来存放另一个命名目录和子文件。最后,指定的目录和子文件将附加到压缩包中,临时目录可以删除。最初打算使用mkdtemp()但它看起来像TemporaryDirectory()方法自己删除?谁能解释一下差异。 最佳答案 您是对的,唯一真正的区别是TemporaryDirectory完成后会自行删除。它会让你做类似的事情:withtempfile.TemporaryDirectory()asdir:do_stuff_with(dir)当您离开with的范围时,临时目录将被删除。使用mkdtemp,您需要手动执行此操作

python - 无法删除由 `tempfile.mkstemp()` 在 Windows 上创建的文件

这是我的示例代码: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