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