[Tutor] Dictionary Format

Bryce Embry bembry@bembry.org
Tue, 05 Mar 2002 16:47:33 -0600


Howdy,
I'm working on a script to help with some Windows 2000 administration and 
have run into a little dictionary glitch that confuses me.  If any of you 
folks can help, I'd really appreciate it.  I've been reading the list for a 
couple months now, but this one is new to me.

I'm using the win32 extensions to get a list of all the users in a windows 
group.  My desire is to then find out if a certain user is a faculty member 
or a student, and make adjustments to the script accordingly.  I get a list 
of users fine, but the format is odd, and I'm not able to then search the 
list to see if a user is part of the given group.

The win32net.NetGroupGetUsers() yields a list with the following dictionaries:

{'name': u'auser'}
{'name': u'buser'}
{'name': u'cuser'}
{'name': u'duser'}
{'name': u'euser'}

auser, buser, cuser, etc. are all the login user names.

I'm trying to extract just the usernames from these dictionaries, but they 
aren't exactly strings (see that goofy little u in front of the 
apostrophe).  If I use a print statement, they work fine.

for item in listofdictionaries:
         print item['name']

 >>>auser
 >>>buser
 >>>cuser

But, if I try to create a new list with just the user names I get the 
following:

[u'auser', u'buser', u'cuser', u'duser']

If I then try to ask if "auser" is in the list, the answer is no.  If I 
slice it, it just cuts off the first letter of the name:

list = []
for item in listofdictionaries:
          list.append(item['name'][1:])

 >>>[u'user', u'user', u'user']

So, what is that extra u before the string markers?   And how do I get past 
it?

Thanks for the help.

Bryce Embry


--------------------------------------------------------------------------------------------
"Lord, you establish peace for us.
All that we have accomplished
you have done for us" -- Isaiah 26:12