[Tutor] Problem with complex strings as key for a shelve-Dictionary

markus kossner m.kossner at tu-bs.de
Sun Sep 6 12:20:19 CEST 2009


Dear all,
I have a Problem with complex strings as keys in a shelve Object:

#!/usr/bin/python
import shelve
test=shelve.open('testshelve')
test={
'CCN1c2ccccc2/C(=C2/S/C(=N\c3ccc(Cl)cc3)N(C)C2=O)C1=O':int(0),
'CN1/C(=N\c2ccc(Cl)cc2)S/C(=C2\C(=O)Nc3ccccc32)C1=O':int(20),
'c1cc2c(cc1)N(CCCl)C(=O)/C2=C1\S/C(=N/c2ccc(F)cc2)NC1=O':float(1),
'Cc1cccc(/N=C2/NC(=O)/C(=C3\c4c(cccc4)N(C)C3=O)S2)c1C':0.5,
}
print test['CCN1c2ccccc2/C(=C2/S/C(=N\c3ccc(Cl)cc3)N(C)C2=O)C1=O']
==> script works without problems

This works fine as long as I keep the shelve opened.
However, when I then want to open the shelve with another python script
I get key errors, as the different keys are not found:

#!/usr/bin/python
import shelve
test=shelve.open('testshelve')
print test['CCN1c2ccccc2/C(=C2/S/C(=N\c3ccc(Cl)cc3)N(C)C2=O)C1=O']
==> leads to key error

I tried raw strings and so on, but did not manage.
Any Ideas?
Cheers Markus



More information about the Tutor mailing list