当我运行我的python脚本来查询用户,它打印在同一行的所有结果(翻译)。打印在python结果垂直,而不是一条线
的代码块在我的Python脚本是:
baseDN = "DC=top,DC=domain,DC=com"
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = ["name"]
searchFilter = "cn=*abc*"
try:
ldap_result_id = l.search(baseDN, searchScope, searchFilter,
retrieveAttributes)
result_set = []
while 1:
result_type, result_data = l.result(ldap_result_id, 0)
if (result_data == []):
break
else:
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
print result_set
except ldap.LDAPError, e:
print e
的上面的结果与此类似水平:
[[('CN=John Doe ,OU=SalesOffices,DC=top,DC=domain,DC=com', {'name': ['John Doe']})], [('CN=Mary Jane,OU=SalesOffices,DC=top,DC=domain,DC=com', {'name': ['Mary Jane']})],
我想它来打印这样竖直:
[[('CN=John Doe ,OU=SalesOffices,DC=top,DC=domain,DC=com', {'name': ['John Doe']})],
[('CN=Mary Jane,OU=SalesOffices,DC=top,DC=domain,DC=com', {'name': ['Mary Jane']})],
谢谢!
结帐的['pprint'](https://docs.python.org/2.7/library/pprint.html?highlight=pprint#module-pprint)模块,例如'from pprint import pprint; pprint(result_set,width = 120)' – AChampion
谢谢,那么我的上面的脚本应该如何打印为垂直列表?我喜欢这个pprint模块(我是编码新手)。另外 - 导入pprint应该在python脚本开始? – Xtos