如何将pickle.dumps
的输出转换为字符串。我需要将输出转换为字符串
目前,我得到的是:
import pickle
class TestClass:
def __init__(self, number):
self.number = number
t1 = TestClass(14)
s1 = pickle.dumps(t1)
str_version = s1.decode('utf-8', 'backslashreplace')
print(pickle.loads(str_version.encode('utf-8', 'backslashreplace')))
但我得到了一个错误:
Traceback (most recent call last):
File "C:\Users\ketha\Downloads\python_testing.py", line 11, in <module>
print(pickle.loads(str_version.encode('utf-8', 'backslashreplace')))
_pickle.UnpicklingError: invalid load key, '\x5c'.
我认为这是因为当我将其转换为字符串时,它将\x5c
(例如)转换为\\x5c
,并且在解码过程中不会撤消它。我怎样才能解开这个
我有一些代码在工作。代码:
相关问题 更多 >
编程相关推荐