私信  •  关注

Nihal

Nihal 最近回复了
3 年前
回复了 Nihal 创建的主题 » 包中的git依赖项。json错误与“拒绝访问(公钥)”?

我使用了带有凭据的https repo URL,它成功了。

谢谢你的回答。

6 年前
回复了 Nihal 创建的主题 » 在Python3.x中查找数组是否存在且不为空

使用 isinstance() 要检查类型,它将返回布尔值

y = {
    "attributes": [
        {
            "name": "test"
        }
    ]
}

# p2 = json.dumps(y)

if 'attributes' not in y:
    print("not found")

else:
    print(y['attributes'])
    print(isinstance(y['attributes'], list))
    if isinstance(y['attributes'], list):
        print('its a list')
        print(len(y['attributes']))
    print("found")

输出:

[{'name': 'test'}]
True
its a list
1
found