class NavigableString(unicode, PageElement):
def __new__(cls, value):
if isinstance(value, unicode):
return unicode.__new__(cls, value)
return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING)
def __getnewargs__(self):#this line
return (NavigableString.__str__(self),)
答案 0 :(得分:10)
试试这个:
x = NavigableString('foop')
y = pickle.dumps(x)
z = pickle.loads(y)
print x, z
即:__getnewargs__
告诉pickle.dumps
挑选x
,以便从该字符串返回的pickle.loads
将NavigableString.__new__
与正确的参数一起使用。