pickle broken:在win32下无法处理NaN或Infinity [英] pickle broken: can't handle NaN or Infinity under win32

查看:77
本文介绍了pickle broken:在win32下无法处理NaN或Infinity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于弄清楚为什么我的某个应用程序有时会在

Win32下失败,因为它在Linux下总能正常工作:在Win32下,

pickle模块只适用于浮点子集

值。特别是如果你试图转储/加载无穷大
或nan值,加载操作扼流圈:

在Linux下:


$ python

Python 2.3.4(#2,2005年2月9日,14:22:48)

[GCC 3.4.1(Mandrakelinux 10.1 3.4.1-) Linux2上的4mdk)]

I finally figured out why one of my apps sometimes fails under
Win32 when it always works fine under Linux: Under Win32, the
pickle module only works with a subset of floating point
values. In particular the if you try to dump/load an infinity
or nan value, the load operation chokes:
Under Linux:

$ python
Python 2.3.4 (#2, Feb 9 2005, 14:22:48)
[GCC 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.



$ python pickletest.py

(inf,nan)(inf,nan )

在Win32下:


$ python

ActivePython 2.3.4 Build 233(ActiveState Corp.)基于

Python 2.3.4(#53,2004年10月18日,20:35:07)[MSC v.1200 32位(英特尔)] on win32

输入help, 版权,信用或许可证或欲了解更多信息。

$ python pickletest.py
(inf, nan) (inf, nan)
Under Win32:

$ python
ActivePython 2.3.4 Build 233 (ActiveState Corp.) based on
Python 2.3.4 (#53, Oct 18 2004, 20:35:07) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.




$ python pickletest.py

Traceback(最近一次调用最后一次):

文件" pickletest.py",第8行,在?

d = pickle.loads(s)

文件C:\ PYTHON23 \ lib \ pickle.py",第1394行,载入

返回Unpickler(文件).load()

文件C:\ PYTHON23 \lib \ pickle.py",第872行,正在加载

dispatch [key](self)

文件" C:\ PYTHON23 \lib \ pickle.py" ,第968行,在load_float中

self.append(float(self.readline()[: - 1]))

ValueError:float()的文字无效:1 。#INF


我意识到这可能是由于Win32 libc implamentation的底层破坏,但应该是pickle模块

隐藏用户的平台依赖性吗?


最好的情况是,如果pickle能够以便携的方式处理所有花车

,那就太好了。


最糟糕的情况是,不应该在pickle模块文件中提到

酸洗浮动非便携式或仅部分建议吗?


在更直接的说明中,是否有pickle钩子允许用户处理pickle无法处理的类型?
?或者,我是否需要抛出泡菜并从头开始写东西?


[NaN和Infinity完全有效(并且非常有用)

浮点值,并且不使用它们将需要巨大的

复杂性增加我的应用程序(不使用它们可能

至少三倍的代码量在某些情况下需要)。


-

格兰特爱德华兹格兰特哇!哇!



visi.com



$ python pickletest.py
Traceback (most recent call last):
File "pickletest.py", line 8, in ?
d = pickle.loads(s)
File "C:\PYTHON23\lib\pickle.py", line 1394, in loads
return Unpickler(file).load()
File "C:\PYTHON23\lib\pickle.py", line 872, in load
dispatch[key](self)
File "C:\PYTHON23\lib\pickle.py", line 968, in load_float
self.append(float(self.readline()[:-1]))
ValueError: invalid literal for float(): 1.#INF

I realize that this is probably due to underlying brokenness in
the Win32 libc implimentation, but should the pickle module
hide such platform-dependancies from the user?

Best case, it would be nice if pickle could handle all floats
in a portable way.

Worst case, shouldn''t the pickle module documentation mention
that pickling floats non-portable or only partially implimented?

On a more immediate note, are there hooks in pickle to allow
the user to handle types that pickle can''t deal with? Or, do I
have to throw out pickle and write something from scratch?

[NaN and Infinity are prefectly valid (and extremely useful)
floating point values, and not using them would require huge
complexity increases in my apps (not using them would probably
at least triple the amount of code required in some cases).]

--
Grant Edwards grante Yow! Yow!
at
visi.com

推荐答案

python

Python 2.3.4(#2,2005年2月9日,14:22:48)

[GCC 3.4.1(Mandrakelinux 10.1 3.4.1-4mdk)] on linux2

键入help,copyright,credit等。或许可证或更多信息。
python
Python 2.3.4 (#2, Feb 9 2005, 14:22:48)
[GCC 3.4.1 (Mandrakelinux 10.1 3.4.1-4mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.


python pickletest.py

(inf, nan)(inf,nan)

在Win32下:

python pickletest.py
(inf, nan) (inf, nan)
Under Win32:


python

ActivePython 2.3.4构建233(ActiveState Corp.)基于

Python 2.3.4(#53,2004年10月18日,20:35:07)[MSC v.1200 32位(英特尔)]在win32上/>
键入help,copyright,credit等。或许可证或了解更多信息。
python
ActivePython 2.3.4 Build 233 (ActiveState Corp.) based on
Python 2.3.4 (#53, Oct 18 2004, 20:35:07) [MSC v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.






这篇关于pickle broken:在win32下无法处理NaN或Infinity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆