如何在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。
答案 0 :(得分:4)
你可以这样做:
import os, pickle
pickle.dumps(str(os.environ))
pickle.dumps(dict(os.environ)) # this also works