我最近安装了 Ubuntu 以与我的 Windows 操作系统一起运行。我想看看某个脚本是如何在 Ubuntu 中运行的,并且大部分情况下运行良好。我的代码中有这一部分会引起麻烦。我尝试使用 os.system('gnome-open ' + filePath) 命令打开文件,但我无法打开文件,除非我只指定文件名而不是目录(即我必须说“数据.txt”,我不能说“home/user/workspace/project/src/data.txt”,因为它会说文件/目录不存在)。此外,我出于测试目的制作了该文件的多个副本,其中一些在其名称中带有括号,当我尝试打开这些文件时,我收到错误“sh:语法错误:”(“意外”并且它没有指定代码行,所以我假设它是' 当我调用这个函数时访问。下面是我引用的代码。
def openFileOfItem(self, row):
print fileList[row]
if platform.system() == "Windows":
os.startfile(fileList[row])
else:
if platform.system() == "Linux":
os.system('gnome-open ' + nameList[row])
else:
os.system('open %s' % fileList[row])
还有一些示例输出:
/home/damian/workspace/Kde Gen/src/data.txt
Error showing url: Error stating file '/home/damian/workspace/Kde': No such file or directory
/home/damian/workspace/Kde Gen/src/data (copy).txt
sh: Syntax error: "(" unexpected