api的学习python的gitlab模块安装pip install python-gitlabimport gitlaburl = ‘http://gitlab.solomon.com/‘token = ‘yApTELsxeZDDTJ_LEDSU‘#得到登录实例gl = gitlab.Gitlab(url,private_token=token)#登录实例获取项目列表obj = gl.projects.list(search=‘flask‘)得到项目列表以后,项目信息如何查看,通过for循环查看列表的元素,列表元素其实是一个类的类型,类似后面的例子下面继续讲gitlab中的例子for i in obj: print(i) print(i.id) #其实就类似类属性的调用方法 print(i.name) print(i.http_url_to_repo) #这都是在i打印出来的字典中可以找到的#gitlab项目名查找时,可能会找出项目名类似的多个项目来,这是我们不希望看到的,下面是一个例子import gitlaburl = ‘http://gitlab.solomon.com/‘token = ‘yApTELsxeZDDTJ_LEDSU‘search_obj_name = ‘flask‘#得到登录实例gl = gitlab.Gitlab(url,private_token=token)#登录实例获取项目列表obj = gl.projects.list(search= search_obj_name)#构造一个字典,清洗数据dic = {}for i in obj: dic[i.name] = i.id #定义字典数据类型for key in dic: #判断字典的键,打印出相应的值 if key == search_obj_name: print( dic[key]) obj2 = gl.projects.get(dic[key]) print(obj2)#######################################################################list = []class student(): def __init__(self,name,sex): self.name = name self.sex = sexa = student(‘solomon‘,‘man‘)class teacher(): def __init__(self,name,sex): self.name = name self.sex = sexb = teacher(‘duke‘,‘man‘)list.append(a)list.append(b)print(list)for i in list: print(i)#感觉才碰到门槛##########################################################################