[Tutor] iterating through large dictionary

Christian Wyglendowski Christian.Wyglendowski at greenville.edu
Tue Mar 22 22:47:19 CET 2005


> -----Original Message-----
> From: tutor-bounces at python.org 
> [mailto:tutor-bounces at python.org] On Behalf Of jeff
> 
> Hi,

Hey Jeff,
 
> I'm trying to print out all the attributes of a user account in active
> directory. I got a script from:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303348
> /index_txt

Hhhmm... I have some code that does basically the same thing, sans the
printing.  Mine looks up the user based on the sAMAccountName instead of
the distinguishedName, though.

> Now I'd like it to print pretty.

[SNIP function]

> user='LDAP://cn=Wardlaw\, Jeff,OU=IS Department,OU=IT
> department,DC=acpdom,DC=acp,DC=edu'
> for k, v in ad_dict(user):
>     print "%s=%s" % (k, v)
> 
> I get the following error when I try this:
> 
> D:\Python24>ad-attr.py
> Traceback (most recent call last):
>   File "D:\Python24\ad-attr.py", line 32, in ?
>     for k, v in ad_dict(user):
> ValueError: too many values to unpack

Try this instead ... I think it should help:

<code>

for k,v in ad_dict(user).items():

</code>

HTH,

Christian
http://www.dowski.com


More information about the Tutor mailing list