Split entries from LDAP

paul paul at subsignal.org
Sun Oct 12 22:07:33 CEST 2008

Lars schrieb:
> I got all the entries in the variable "raw_res" and I now got some
> doubts on how to split each value up in every entry. Belove you can
> see one of entries printed from the loop.
> cn=world.dom.dk,ou=Hosts,o=Users,dc=dom,dc=dk', {'ipHostNumber':
> [''], 'cn': ['world.dom.dk'], 'description':
> ['Mail&webserver']})"
> I've tried different things, but don't quite know to split the tuple.
search_s() returns a tuple of lenght 2. The first entry is the DN, the 
second entry is a dictionary with attributes as keys and lists of values 
as values. Possible function to handle this (untested):

def print_entry(entry):
   print "Got Entry for DN: %s" % entry[0]
   print "Attributes:"
   for key, value in entry[1].items():
     print "\tKey: %s" % key
     print "\tValue(s): %s" ", ".join(value)

the ", ".join(value) creates a string from a list, check the docs for 
dictionaries for other syntax elements.


More information about the Python-list mailing list