当保存excel文件(openpyxl),然后尝试使excel在mac上打开获取`Permission denied`错误

此代码:

workbook.save(outputf) system('open ' + outputf) 

在我的mac上运行时产生这个错误:

 sh: /Users/tylerjw/Desktop/jim_data/August2013_report.xlsx: Permission denied 

该文件是用openpyxl创build的。 我没有能够重现我的应用程序之外的错误是一个tkinter应用程序正在写入大量的数据到该文件。

当我在Windows中运行类似的代码时,它不会出错,它会打开文件的excel。 唯一的区别是没有open命令。

什么可能会发生这种错误?

在我的系统(mac 10.6.8,python2.7.5,gcc 4.2.1)下面的代码工作正常:

 from openpyxl import Workbook from os import system wb = Workbook() outputf = 'test.xlsx' wb.save(outputf) # see below * system('open ' + outputf) 

(请参阅评论:我输了这个赌注,错误是在代码中的其他地方,与系统无关('open'+ whatever))

我敢打赌,你的系统上的新文件的权限有问题。 也许你添加( 文件 )

 st = os.stat(outputf) os.chmod(outputf, st.st_mode | stat.stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) 

(从其他链接input)

在代码中而不是我的评论('#see below *')然后,应该可以打开它的所有人和所有…

如果有效,这是一个解决方法。 我们的系统有一个区别,我不知道有什么区别。 如果没有,那么我没有在我的系统上testing它(因为我没有代码问题),写一个评论,我可能会玩这个设置,也许别人有一个想法。

顺便说一句:在你的文件夹中的terminal:执行Python代码后输出“ls -l excelfilename”的输出是什么? 你使用什么编程环境? 我通过terminal中的“python2.7 pythonscript.py”启动程序。