在 python 中,打开 tmpfile 的位置时出错:不存在这样的文件或目录

In python, Error opening location of tmpfile: No such file or directory exist

我正在学习 Philip Klein 的 'Coding the matrix'。在第二章中,有一个绘制复数的例子

from plotting import plot

S = {2+2j, 3+2j, 1.75+1j, 2+1j, 2.25+1j, 2.5+1j, 2.75+1j, 3+1j, 3.25+1j}

plot(S, 4)

绘图模块:http://resources.codingthematrix.com

当我 运行 直接通过终端中的 python 代码时,它工作正常,但是当我 运行 它作为单独的文件时 "$ python example.py",我得到这个错误:

gvfs-open: file:///tmp/tmpOYFVs8.html: error opening location: Error 
when getting information for file '/tmp/tmpOYFVs8.html': No such file 
or directory

不知道如何解决这个问题。试着玩了一下模块代码,但一无所获。

我检查了 plotting.py 的代码,发现在代码末尾注册了 atexit 事件,当您的程序 exits.So 当您将其作为脚本调用时,该事件基本上会删除文件 python 解释器退出,实习生将调用 atexit 寄存器删除文件。

def remove_at_exit(path):
   atexit.register(os.remove, path)

可以直接注释掉第92行plotting.py中对remove_at_exit方法的调用

打开 plotting.py 然后修补这个

hpath =  os.getcwd() + "/something.html"

取而代之或在此之后的一行

hpath = create_temp('.html')