[Python] python读取LDIF文件 →→→→→进入此内容的聊天室

来自 , 2019-07-08, 写在 Python, 查看 118 次.
URL http://www.code666.cn/view/04fcc654
  1. #!/usr/bin/python
  2. # -*- coding: iso-8859-1 -*-
  3.  
  4. import ldif  # ldif module from http://python-ldap.sourceforge.net
  5.  
  6. class testParser(ldif.LDIFParser):
  7.     def __init__(self,input_file,ignored_attr_types=None,max_entries=0,process_url_schemes=None,line_sep='\n' ):
  8.       ldif.LDIFParser.__init__(self,input_file,ignored_attr_types,max_entries,process_url_schemes,line_sep)
  9.    
  10.     def handle(self,dn,entry):
  11.         if 'person' in entry['objectclass']:
  12.             print "Identifier = ",entry['uid'][0]
  13.             print "FirstName = ",entry.get('givenname',[''])[0]
  14.             print "LastName = ",entry.get('sn',[''])[0]
  15.             print
  16.  
  17. f = open('myfile.ldif','r')
  18. ldif_parser = testParser(f)
  19. ldif_parser.parse()
  20. #//python/1873

回复 "python读取LDIF文件"

这儿你可以回复上面这条便签

captcha