Python os.remove失败(unicode对象?)

Python os.remove失败(unicode对象?),python,temporary-files,Python,Temporary Files,我的python脚本从一个网站读取JSON信息,将其存储在一个文件中进行处理,并最终将其清除 这在其他脚本中正常工作,但由于某些原因,os.remove最终无法删除该文件: import urllib2, json import os, sys, argparse ref_list_tmpfile = '/tmp/reference.%s.txt' % os.getpid() ref_list_response=urllib2.urlopen('http://localhost:11111/

我的python脚本从一个网站读取JSON信息,将其存储在一个文件中进行处理,并最终将其清除

这在其他脚本中正常工作,但由于某些原因,os.remove最终无法删除该文件:

import urllib2, json
import os, sys, argparse


ref_list_tmpfile = '/tmp/reference.%s.txt' % os.getpid()
ref_list_response=urllib2.urlopen('http://localhost:11111/api/reference').read()

with open(ref_list_tmpfile,'w') as outfile:
outfile.write(ref_list_response)

ref_list_data=open(ref_list_tmpfile)
reference_list = json.load(ref_list_data)
ref_list_data.close()
.
.
.
.
os.remove(ref_list_tmpfile)
主逻辑工作正常,但我收到的错误是指最后一个命令(os.remove),文件未被删除:

Traceback (most recent call last):
  File "./vm_creator.py", line 58, in <module>
    os.remove(ref_list_tmpfile)
AttributeError: 'unicode' object has no attribute 'remove'
回溯(最近一次呼叫最后一次):
文件“/vm_creator.py”,第58行,在
删除操作系统(参考列表文件)
AttributeError:“unicode”对象没有属性“remove”

有什么想法吗?

你已经将
os
重新定义为一个字符串,在你剪切的代码中的某个地方。

是的,就是这样。谢谢