小编Ali*_*dra的帖子

模块“gitlab”没有属性“Gitlab”

我正在尝试从 gitlab 读取该文件。我为此在 gitlab 中创建了访问令牌。下载的模块 python-gitlab

我从 PyCharm 安装了模块 python-gitlab:文件 --> 设置 --> Python 解释器 --> python-gitlab

import gitlab
import json
from pprint import pprint
import requests
import urllib.request
# private token authentication
gl = gitlab.Gitlab('https://gitlab.com/..../CSV_HOMEWORK.csv', private_token='xxx')

gl.auth()

# list all projects
projects = gl.projects.list()
for project in projects:
    # print(project) # prints all the meta data for the project
    print("Project: ", project.name)
    print("Gitlab URL: ", project.http_url_to_repo)
    # print("Branches: ", project.repo_branches)
    pprint(project.repository_tree(all=True))
    f = urllib.request.urlopen(project.http_url_to_repo)
    myfile = …
Run Code Online (Sandbox Code Playgroud)

python gitlab

4
推荐指数
1
解决办法
6781
查看次数

检查字典是否为空但有键

我有一本字典,可能只有这些键。但可以有 2 个键,例如'news'and'coupon'或 only 'coupon'。如何检查字典是否为空?(下面的词典是空的。)

{'news': [], 'ad': [], 'coupon': []}
{'news': [], 'coupon': []}
Run Code Online (Sandbox Code Playgroud)

我写了代码,但它应该只需要 3 个键:

if data["news"] == [] and data["ad"] == [] and data["coupon"] == []:
    print('empty')
Run Code Online (Sandbox Code Playgroud)

怎样才能不只带3把钥匙?

python dictionary is-empty

1
推荐指数
1
解决办法
2654
查看次数

标签 统计

python ×2

dictionary ×1

gitlab ×1

is-empty ×1