從 ldap 搜索結果中獲取此串列,嘗試決議為 csv。但是必須先過濾掉None。但獲得與 search_res 相同的內容。我做錯了什么?
搜索資源:
[('CN=GON,OU=App,OU=Groups,DC=com', {'member': [b'CN=user1,OU=Users,DC=com', b'CN=user2,OU=Users,DC=com',]}), (None, ['ldap://skogen.com/CN=Sche,CN=Conf,DC=com']), (None, ['ldap://skogen.com/CN=Sche,CN=Conf,DC=com'])]
拉姆達:
lame = lambda x: (x is not None)
list_out = list(filter(lame, search_res))
print(list_out)
我想要的 csv 只是:
user1
user2
uj5u.com熱心網友回復:
您串列的條目是元組,您正在檢查元組是否為無。但是,您似乎想要檢查元組的第一個元素是否不是 None。因此,您已將過濾器功能更改為
lame = lambda x: (x and x[0] is not None)
這現在檢查整個 None 元素和第一個元素不是 None。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/427614.html
下一篇:如何添加到List<int,string>動態id(int)內部的每個專案(字串),這實際上是內部每個元素的位置?
