Search code examples
pythonldap-query

Printing in python the result vertical instead of one line


when i run my python script to query a user, it prints all the results in one line(in the interpreter.)

the block of code in my python script is:

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

the result of the above is similar to this horizontally:

[[('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']})],

I would like it to print like this vertically:

[[('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']})],

Thanks!


Solution

  • Instead of print result_set, use:

    for x in result_set:
        print x