On 2010-07-12, Alexander Eisenhuth <newsu...@stacom-software.de> wrote:
> python: 2.5.1 > palttform: winXP > > I'm using pickle.dump and pickle.load with data that is created in a > wrapped (boost.python) piece of C++ code. pickle.dump works fine. > pickle.load creates the following exception: > > [...] > data = pickle.load(input) > File "C:\Python25\lib\pickle.py", line 1370, in load > return Unpickler(file).load() > File "C:\Python25\lib\pickle.py", line 858, in load > dispatch[key](self) > File "C:\Python25\lib\pickle.py", line 954, in load_float > self.append(float(self.readline()[:-1])) > ValueError: invalid literal for float(): -1.#IND > > - I'm not sure what -1.#IND means. That's an infinity. > Can somebody assist? In Python 2.x, pickle doesn't handle infinities and NaNs. > - As pickle write the data I'm a bit confused, that is can't be > unpickled it. Is that a bug or a feature? IMO, it's a bug. It's been fixed in 3.x. > BTW: I'm tied to version 2.5 of python If you want to pickle floating point data that includes infinities and NaNs, you need to write your own handler for floating point values. When pickling you need to check for infinities and NaNs and output some defined strings. When unpickling, you need to check for those strings and generate infinities and NaNs as appropriate. The CPython 2.x version of pickle just uses the underlying C library routines to print and parse floating point values. If those libraries are broken in the way that they represent infinity and NaN, then pickle is broken in the same manner. Windows standard libraries are broken. When formatting floating point values, it produces strings that it can't parse as input. IIRC, Linux works better -- but if you want something that you know is going to work (and work cross-platform), then you need to write your own floating point pickle/unpickle methods, and hook them into the pickle module. -- Grant Edwards grant.b.edwards Yow! Uh-oh!! I'm having at TOO MUCH FUN!! gmail.com -- http://mail.python.org/mailman/listinfo/python-list