Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def retry(f, n_attempts=3):
- # 包装函数,在函数异常时尝试多次调用,这里是尝试3次
- def wrapper(*args, **kwargs):
- for i in range(n_attempts):
- try:
- return f(*args, **kwargs)
- except Exception:
- if i == n_attempts - 1:
- raise
- return wrapper
- # 金融数据包
- import tushare as ts
- # 避免某次调用get_hs300s方法失败
- hs300 = retry(ts.get_hs300s)()
Add Comment
Please, Sign In to add comment