New submission from David Nicolson <david.nicol...@gmail.com>:
Converting float values stored as strings with the real data type can result in an integer value or a rounding error. import plistlib xml = """<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>FloatExample</key> <real>100.0</real> <key>FloatExample2</key> <real>0.1</real> </dict> </plist> """ pl = plistlib.loads(str.encode(xml), fmt=plistlib.FMT_XML) with open('test.plist', 'wb') as fp: plistlib.dump(pl, fp, fmt=plistlib.FMT_BINARY) cat test.plist | plutil -convert xml1 -o - -- - <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>FloatExample</key> <real>100</real> <key>FloatExample2</key> <real>0.10000000000000001</real> </dict> </plist> This might be related to the following issue: https://bugs.python.org/issue14896 ---------- messages: 356440 nosy: David Nicolson priority: normal severity: normal status: open title: plist handling of real data type type: behavior versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38777> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com