晚上好,我有这种类型的 python 对象。这里有什么方法可以将它转换为字符串、编辑并转换回来吗?
<class 'matplotlib.transforms.CompositeGenericTransform'>
当我通过 print(variable) 打印它时,它看起来像这样:
CompositeGenericTransform(CompositeGenericTransform(CompositeGenericTransform(CompositeGenericTransform(CompositeGenericTransform(TransformWrapper(BlendedAffine2D(IdentityTransform(),IdentityTransform())), CompositeGenericTransform(BboxTransformFrom(TransformedBbox(Bbox('array([[ -19.5 , -10.7983871],\n [ 221.5 , 140.7983871]])'), TransformWrapper(BlendedAffine2D(IdentityTransform(),IdentityTransform())))), BboxTransformTo(TransformedBbox(Bbox('array([[ 0.125, 0.25 ],\n [ 0.9 , 0.9 ]])'), BboxTransformTo(TransformedBbox(Bbox('array([[ 0., 0.],\n [ 8., 6.]])'), Affine2D(array([[ 80., 0., 0.],
[ 0., 80., 0.],
[ 0., 0., 1.]])))))))), Affine2D(array([[ 0.99968918, -0.02493069, 6.98903935],
[ 0.02493069, 0.99968918, -8.59039721],
[ 0. , 0. , 1. ]]))), Affine2D(array([[ 0.99968918, -0.02493069, 6.93499095],
[ 0.02493069, 0.99968918, -7.14592338],
[ 0. , 0. , 1. ]]))), Affine2D(array([[ 0.99968918, -0.02493069, 6.88226449],
[ 0.02493069, 0.99968918, -6.30113809],
[ 0. , 0. , 1. ]]))), Affine2D(array([[ 0.99968918, -0.02493069, 6.96735103],
[ 0.02493069, 0.99968918, -7.27368166],
[ 0. , 0. , 1. ]])))
最佳答案
你可以用 Pickle 做到这一点,它是 Python 的对象序列化库。
关于python - 将 python 对象转换为字符串,编辑它并转换回原始类型的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21322151/