在python循环中打印出特定的键
我正试图从循环中打印某个密钥,但遇到了一些问题。尝试搜索其他响应,但仍有问题在python循环中打印出特定的键,python,json,python-2.7,list,loops,Python,Json,Python 2.7,List,Loops,我正试图从循环中打印某个密钥,但遇到了一些问题。尝试搜索其他响应,但仍有问题 import json from azure.graphrbac import GraphRbacManagementClient from azure.graphrbac.models import UserCreateParameters, PasswordProfile from azure.common.credentials import UserPassCredentials admin_user_nam
import json
from azure.graphrbac import GraphRbacManagementClient
from azure.graphrbac.models import UserCreateParameters, PasswordProfile
from azure.common.credentials import UserPassCredentials
admin_user_name = ''
admin_password = ''
# e.g. yourcompany.onmicrosoft.com
tenant_id = ""
credentials = UserPassCredentials(
admin_user_name,
admin_password,
resource="https://graph.windows.net"
)
graphrbac_client = GraphRbacManagementClient(
credentials,
tenant_id
)
users = graphrbac_client.users.list();
for user in users:
print [user['mail_nickname']]
我只想提取的密钥名为mail\u昵称
我得到这个错误
TypeError: 'User' object has no attribute '__getitem__'
我只做打印(用户)
,工作正常,但加载不需要的数据
任何帮助都将不胜感激。谢谢尝试使用
user.mail\u昵称
而不是user['mail\u昵称]
。
当对象不支持使用括号(如user['id']
)的get
运算符时,会发生错误
或者尝试
打印(dir(user))
。它将帮助您检查您可以使用的属性。它不只是用户的属性吗
,例如用户.mail\u昵称
?