为什么列表的长度在我的代码中显示为零?

时间:2014-02-24 14:44:37

标签: python python-2.7 python-ldap

import ldap

try:
    l = ldap.initialize("ldap://ldap.xxxxx.com:389")
    username=raw_input("Enter the username : ")
    password = raw_input("Enter the password :")
    if(username == "" or password==""):
        print "Login Error : Username or password can't be blank"    
    else:
        l.simple_bind(username,password)
        print "Contact..."

except ldap.LDAPError, e:
    print e

baseDn = "ou=active, ou=employees, ou=people, o=xxxxx.com";
searchScope = ldap.SCOPE_ONELEVEL
#retrieve all attributes
retrieveAttributes = None
search_query = raw_input("Enter the query :")
searchFilter = "cn="+search_query

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

    print len(result_set)   

except ldap.LDAPError, e:
    print e

#print result_set[0]

上面的代码使用python-ldap来访问ldap服务。 result_set类型显示为列表,但使用len()函数时的项数变为零。我需要对检索到的字符串执行操作。

0 个答案:

没有答案