简体   繁体   English

咸菜和象征性表达的评估

[英]Pickle and evaluation of sympy expressions

I have the problem that pickling/unpickling of sympy expressions may not return the inital expression, as in the following example 我有一个问题,即对表达式表达式进行腌制/取消腌制可能不会返回初始表达式,如以下示例所示

>>>with evaluate(False) : x = atan(sqrt(3))
>>>x
atan(sqrt(3))
>>> y = pickle.dumps(x)
>>> z = pickle.loads(y)
>>> z
pi/3

Is there a way to avoid the evaluation in the process? 有没有办法避免评估过程?

The motivation is that I need to add sympy expressions to a request.session object in Django without them being altered in the process. 这样做的动机是我需要在Django中将sympy表达式添加到request.session对象中,而无需在过程中对其进行更改。

The comment by user2357112 answers the question. user2357112的评论回答了该问题。

>>>with evaluate(False) : x = atan(sqrt(3))
>>>x
atan(sqrt(3))
>>> y = pickle.dumps(x)
>>> with evaluate(False) : z = pickle.loads(y)
>>> z
atan(sqrt(3))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM