我有一个代码的List输出,我在python中工作,我特意在寻找'cn'
字符串,并希望之后的每个名字都打印到新行:
喜欢:
anshulm
jiafan
并且在快速获取这些名称时,[[('cn=oracle,ou=Group,ou=corp,ou=services,o=kk.com', {'description': ['oracle group'], 'businessCategory': ['Private'], 'objectClass': ['top', 'groupOfUniqueNames', 'posixGroup'], 'memberUid': ['anshulm', 'jiafan', 'manasij', 'asbisht', 'karnika', 'junle', 'amitsh', 'fuwei', 'dewansh', 'gouravr', 'harshitb', 'tandel', 'matte', 'izamir', 'elie', 'emiliano', 'mateuszw', 'theo', 'mahdi', 'hassan', 'gshruti', 'makhiles', 'prabhaka', 'shgarg', 'ritolia', 'wadhwani', 'steev', 'rtlsbld', 'nikhilb', 'fwang', 'ankitb', 'rtls', 'amitb', 'agautam', 'pratyush', 'hywang', 'dsouder', 'foutz', 'parimi', 'pradeepn', 'patrickg', 'pkunwar', 'tejinder', 'ramteke', 'jangra', 'kush', 'kundan', 'mohang', 'xiang', 'xinjia', 'anantv', 'christos', 'achugh', 'kbhatt', 'jroy', 'kusantos', 'kamleshm', 'iraa', 'indrajit'], 'gidNumber': ['9393'], 'owner': ['varshney'], 'cn': ['oracle']})]]
只会停止打印。
import ldap
## first you must open a connection to the server
try:
l = ldap.initialize("ldap://ldapserver:389")
l.protocol_version = ldap.VERSION3
except ldap.LDAPError, e:
print e
baseDN = "ou=group,ou=corp,ou=services,o=kk.com"
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
searchFilter = raw_input("Enter the Group Name: ")
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
以下是我的代码,它产生了上述输出:
/**
* Do something
*
* @Route("/synchro", name="app_synchro")
*/
public function synchroAction(Request $request){
//code here etc...
}
答案 0 :(得分:0)
您应该从result_set
中提取所需的部分,例如:
result_set[0][0][1]['memberUid']
并以您喜欢的任何方式打印:
from pprint import pprint
pprint(result_set[0][0][1]['memberUid'])
或
print('\n'.join(name for name in result_set[0][0][1]['memberUid']))