问题
I have an Excel open which has RTD streaming data (financial data from a trading platform). My goal is read the data by Python and save it as soon as it changes. The goal is to capture every milisecond. I am using xlwings to read the cell value but usually after 50-100 attempts I got the same error. Any idea how to solve it?
import xlwings as xw
n_of_times_checked=0
while True:
n_of_times_checked +=1
print("Cell value:",xw.Range("D41").value," Num of times checked:",n_of_times_checked)
The result:
Cell value: 55.0 Num of times checked: 71
Cell value: 55.0 Num of times checked: 72
Cell value: 55.0 Num of times checked: 73
Cell value: 55.0 Num of times checked: 74
Cell value: 55.0 Num of times checked: 75
Traceback (most recent call last):
File "D:/Google drive/Python/Backtesting/backtesting_uj/RTD_recorder.py", line 7, in <module>
print("Cell value:",xw.Range("D41").value," Num of times checked:",n_of_times_checked)
File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\main.py", line 999, in __init__
impl = apps.active.range(cell1).impl
File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\main.py", line 392, in range
return Range(impl=self.impl.range(cell1, cell2))
File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\_xlwindows.py", line 401, in range
xl1 = self.xl.Range(arg1)
File "C:\Users\Laci\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlwings\_xlwindows.py", line 63, in __call__
v = self.__method(*args, **kwargs)
File "<COMObject <unknown>>", line 2, in Range
pywintypes.com_error: (-2147352573, 'Member not found..', None, None)
回答1:
I was looking for help since I do not get, as you a value, I just get #¿NAME? with my code although keying F2 F9 get the right value (rtd.tos). Anyhow, I guess the problem is your code crashes when looking for a value while it is changing/refreshing, so I would suggest using try/except wrapping your print statement. Also, beware that rtd in refreshing rate according to Application.RTD.ThrottleInterval value (default 1 second).
来源:https://stackoverflow.com/questions/55422990/xlwings-error-pywintypes-com-error-2147352573-member-not-found-none-no