0
我最近在我的Mac安裝xlwings,我目前試圖寫一個小程序來更新一些數據(通過請求)。作爲一項測試,我試圖通過API更新cryptocurrency價格並將它們寫入excel。 不使用runpython,代碼有效。但是當我跑我的VBA代碼, 我得到這個錯誤:xlwings runpython EOL錯誤
File "<string>", line 1
import sys, os;sys.path.extend(os.path.normcase(os.path.expandvars('/Users/Dennis/Documents/crypto;
^
SyntaxError: EOL while scanning string liberal
我已搜查多個線程和論壇,但似乎無法找到答案我的問題。 爲了更好地理解,
我的Python代碼:
import requests, json
from datetime import datetime
import xlwings as xw
def do():
parameter = {'convert' : 'EUR'}
#anfrage über API
query_ticker = requests.get('https://api.coinmarketcap.com/v1/ticker', params = parameter)
#anfragedaten in JSON-format
data_ticker = query_ticker.json()
wb = xw.Book.caller()
ws0 = wb.sheets['holdings']
for entry in data_ticker:
# update eth price
if entry['symbol'] == 'ETH':
ws0.range('B14').value = float(entry['price_eur'])
#update btc price
if entry['symbol'] == 'BTC':
ws0.range('B15').value = float(entry['price_eur'])
if entry['symbol'] == 'NEO':
ws0.range('B16').value = float(entry['price_eur'])
if entry['symbol'] == 'XRP':
ws0.range('B17').value = float(entry['price_eur'])
now = datetime.now()
write_date = '%s.%s.%s' %(now.day, now.month, now.year)
write_time = '%s:%s:%s' %(now.hour, now.minute,now.second)
ws0.range('B2').value = write_date
ws0.range('B3').value = write_time
wb.save('holdings.xlsm')
#wb.close()
這是我的VBA代碼:
Sub update_holdings()
RunPython ("import update_holdings; update_holdings.do()")
End Sub
從您發佈的錯誤的外觀上來看,你可能會丟失從一個字符串賦值 – jsotola
對於我來說,似乎更多的是單引號字符,有一些錯誤的文件路徑傳遞的方式。然而,我沒有絲毫的線索知道'import sys [..]'錯誤是指什麼,或者它試圖對我說什麼?正如你在我的代碼中看到的,我沒有使用sys模塊。 – ohlawd
編輯:我剛剛下載了xlwings斐波那契示例文件,它引發了完全相同的錯誤。可能是PYTHONPATH的東西?問題,我在這方面不是很有經驗.. – ohlawd