当前位置: 移动技术网 > IT编程>脚本编程>Python > python链式调用REST API把参数放到URL中

python链式调用REST API把参数放到URL中

2019年12月18日  | 移动技术网IT编程  | 我要评论

花落燕云梦全文阅读,好听的dj舞曲,南充职业技术学院录取查询

需求格式:get /users/:user/repos

程序:

 1 class chain(object):
 2     def __init__(self,path=''):
 3         self._path=path
 4 
 5     def __getattr__(self, path):
 6         return chain( '%s/%s' %(self._path,path))
 7 
 8     def __str__(self):
 9         return self._path
10 
11     def __call__(self, user):
12         return chain('%s/%s' %(self._path,user))
13 
14     __repr__=__str__

实例:

1 print('get',chain().users('michael').repos)
2 print('get',chain().status.user.timeline.list)

结果:

1 get /users/michael/repos
2 get /status/user/timeline/list

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网