I have this bit of code part of a python script i have to query ldap attributes of users:
try:
ldap_result_id = l.search(baseDN, searchScope, get_searchFilter(adname),
retrieveAttributes)
result_set = []
while 1:
result_type, result_data = l.result(ldap_result_id, 0)
if (result_data == []):
break
else:
## you could do whatever you want with the individual entry
## The appending to list is just for illustration.
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
for x in result_set:
print x
except ldap.LDAPError, e:
print e
print ldap.LDAPError
How can I clean this up and make it into a reusable function(or is Method the more proper terminology)?