今天早上准备写一个实盘行情入库。用的tushare的库。代码如下
df = ts.get_realtime_quotes('sh000300')
sz50 = ts.get_realtime_quotes('sh000016')
zz500 = ts.get_realtime_quotes('sh000905')
print(df[['code', 'name', 'price', 'bid', 'ask', 'volume', 'amount', 'time']])
code = df['code'][0]
name = df['name'][0]
price = df['price'][0]
bid = df['bid'][0]
ask = df['ask'][0]
volume = df['volume'][0]
amount = df['amount'][0]
time = df['time'][0]
time.sleep(0.5)
我想本想sleep下,然后报错了
AttributeError: ‘str’ object has no attribute ‘sleep’
解决方案:
方案一:
将from time import换成import time
方案二:
检查是否有定义名称为time的变量,如有换位其他名称,避免重复。
这个小问题很多人都会遇到