在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昵称