Dictionary checking

Bjørn Ove Grøtan bgrotan at stud.ntnu.no
Thu May 30 03:36:08 EDT 2002


Kragen Sitaker wrote:
> 
> Bjørn Ove Grøtan  <bgrotan at stud.ntnu.no> writes:
> > I'm building a dictionary with values from a file.
> >
> > for each key, I have an ID, Name and Alias
> > some keys I have only ID and Name, some keys with
> > ID and Alias, some keys with all 3 and a few keys
> > with only a ID with no Name and no Alias.
> 
> So your file looks something like this?
> JKJ30 id=foo name=bar alias=baz
> JKJ31 id=quux name=blort
> JKJ32 id=bloozie alias=znap
> 
> > How can I check if Name and/or Alias contain anything.
> 
> Well, that depends on your file format and your internal
> representation.

Every X minutes this file is generated.. from time to time I will
not know 100% of the contents.. my dict looks like this:
If my input is from file or STDIN makes no difference... the dict
should/will be build anyways..

oudict[depID] = parentID, depName, depAlias
I do a readline-routine to put data from input-file, and splits
on ";" 

for each depID, the dict stores parentID, depName and depAlias

after successfully building the dict, I have the following code:
for depID in oudict.keys():
	if filter(lambda x: x>'\x7f', oudict[depID][1]):
        	ouldif.write("dn:: ",)
        else:
                ouldif.write("dn: ",)
        currentID = depID
        while 1:
                        oustr = oudict[currentID][1]
			# if oudict[currentID][1] contains nothing.. 
			# I must use [2] instead of [1].. a simple compare.. 
			# this is basically what I want to do.. if [1] is "" and
			# [2] is "" I want to reject that depID and put that depID
			# into an output-file
                        if filter(lambda x: x>'\x7f', oustr):
                                ouldif.write(base64.encodestring("ou=" +
oustr + ",",))
                        else:
                                ouldif.write(" ou=" + oustr)
                        if currentID == oudict[currentID][0]: break     
                        currentID = oudict[currentID][0]                
                ouldif.write("\n")
                ouldif.write("objectClass: top \n")
                ouldif.write("objectClass: organizationlunit \n")
                if filter(lambda x: x>'\x7f', oustr):
                        ouldif.write("ou: " +
base64.encodestring(oudict[currentID][1]))
                else:
                        ouldif.write("ou: " + oudict[currentID][1])
                ouldif.write("\n \n")

the second question is, I'm building another dict-> persondict()
persondict[recID] = depIDrel, pnummer, pansnum, pnavn, pstilling,
pfunksjon

when I'm building output from persondict() I want to map the value of
depName or depAlias from oudict() with info from persondict(). depIDrel
in persondict() corresponds with the
appropriate value of depID in oudict()

Best regards

Bjørn



More information about the Python-list mailing list