如何在Python 3中腌制os.environ?

时间:2017-06-15 14:38:09

标签: python python-3.x pickle

如何在Python 3中挑选os.environ

>>> import os, pickle
>>> pickle.dumps(os.environ)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: Can't pickle local object '_createenviron.<locals>.decode'

上述内容适用于Python 2。

1 个答案:

答案 0 :(得分:4)

你可以这样做:

import os, pickle

pickle.dumps(str(os.environ)) 
pickle.dumps(dict(os.environ))  # this also works