From: chuck c. <cc...@zi...> - 2002-03-13 01:32:23
|
I'm using Jython for my project and today we tried adding the functionality where you can save out a Config object and then when you restart you can load a Config if you need it. I'm using the java.io libraries to do this because I can't assume pickle or any of the other python libraries are on the machine. However I ran into an issue where after reading the serialized object in some statements which checked to see if an attribute on the object is None were failing. I've recreated the problem in the code snippet below as succinctly as I can. Does anyone have any ideas on what I'm doing wrong? I have a feeling it must be something really simple or could this be a bug in Jython? TIA chuck -------code------- from java.io import * from org.python.util import * class Test(Serializable): def __init__(self): self.attr = None def test(self): print "attr is None:", self.attr is None print "attr type is:", type(self.attr) print "attr == None:", self.attr == None def load(path): file = File(path) fileIn = FileInputStream(file) pyIn = PythonObjectInputStream(fileIn) pyObj = pyIn.readObject() pyIn.close() return pyObj def save(obj, path): fileOut = FileOutputStream(path) objOut = ObjectOutputStream(fileOut) objOut.writeObject(obj) objOut.flush() objOut.close() print "Testing initial object..." a = Test() a.test() save(a, "test.out") b = load("test.out") print "Testing deserialized object..." b.test() -----results---- Testing initial object... attr is None: 1 attr type is: org.python.core.PyNone attr == None: 1 Testing deserialized object... attr is None: 0 attr type is: org.python.core.PyNone attr == None: 0 I would expect that if the attribute is of Type PyNone then it should return 1 to attr is None and attr == None I thought the problem might be that between serializing/deserializing I might somehow be getting a different instance of PyNone but this isn't the case as evidenced below when I inspect the objects in the interpreter after running th code above >>> type(a.attr) <jclass org.python.core.PyNone at 334527779> >>> type(b.attr) <jclass org.python.core.PyNone at 334527779> |