[Pyobjc-dev] Problem with conversion of NSNumbers and property lists
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2003-03-05 14:34:35
|
I ran into a little snag regarding the current treatment of NSNumber, esp. the conversion to python numbers. The following scriptlet writes a plist containing two keys 'int' and 'bool', with the current version of the bridge both have an integer value (tag <integer>). > from Foundation import NSMutableDictionary, NSNumber > > d = NSMutableDictionary.dictionary() > d['int'] = 1 > d['bool'] = NSNumber.numberWithBool_(1) > > d.writeToFile_atomically_("foo.plist", 0) My problem is that I wanted to write a boolean value for key 'bool', <true/> instead of <integer>1</integer>. Python might not care about the difference between booleans and integers, but I ran into a program that does care. If I disable the conversion of NSNumbers to Python numbers my script writes a plist containing <true/> and <false/> tags and the target program interpretes my plist as expected. Ideas? Should we introduce our own boolean type on python 2.2 (aliasing the builtin bool type on 2.3)? Ronald P.S. This is with python 2.2, in Python 2.3 this is less of a problem because python booleans are then converted to boolean NSNumbers. |