我是Python新手,正在调试我编写的使用xlwings的脚本。它用于从电子表格前端拉入函数输入。在
从我在文档中发现的,这似乎是调试它的方法(在Spyder中):
import os
from xlwings import Workbook, Range
def my_macro():
wb = Workbook.caller()
Range('A1').value = 'Hello xlwings!'
if __name__ == '__main__':
# Mock the calling Excel file
Workbook.set_mock_caller(r'C:\path\to\file.xlsx')
my_macro()
但是,当我使用相同的格式运行我的代码时(从Spyder而不是excel vba中)。。。。在
^{pr2}$然后我得到以下错误:
Traceback (most recent call last):
File "<ipython-input-104-07b9dac99d09>", line 1, in <module>
runfile('S:/.../Optimiser')
File "C:\Users\abutkovi\Anaconda3_64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 585, in runfile
execfile(filename, namespace)
File "C:\Users\abutkovi\Anaconda3_64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "S:/.../Optimisation.py", line 210, in <module>
optimisation_wrapper()
File "S:/.../Optimisation.py", line 122, in optimisation_wrapper
wb = xw.Workbook.caller()
File "C:\Users\abutkovi\Anaconda3_64\lib\site-packages\xlwings\main.py", line 230, in caller
_, xl_workbook = xlplatform.get_open_workbook(Workbook._mock_file)
TypeError: 'NoneType' object is not iterable
同样,当我尝试在ipython控制台中设置一个模拟调用者时,它会出现相同的错误消息。在
任何关于如何调试脚本的建议将不胜感激!在
目前没有回答
相关问题 更多 >
编程相关推荐