在Python,MATLAB等中使用eval [英] Use of eval in Python, MATLAB, etc

查看:95
本文介绍了在Python,MATLAB等中使用eval的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实知道不应该使用eval.出于所有显而易见的原因(性能,可维护性等).我的问题更多是在一边–是否有合法用途?应该在哪里使用它而不是以另一种方式实现代码.

I do know that one shouldn't use eval. For all the obvious reasons (performance, maintainability, etc.). My question is more on the side – is there a legitimate use for it? Where one should use it rather than implement the code in another way.

由于它是用多种语言实现的,并且会导致不良的编程风格,所以我认为有一定理由仍然可以使用它.

Since it is implemented in several languages and can lead to bad programming style, I assume there is a reason why it's still available.

推荐答案

首先,这是 Mathwork替代eval的列表.

您也可能很聪明,可以在已编译的应用程序中使用eval()来构建mCode解释器,但是Matlab编译器出于明显的原因不允许这样做.

You could also be clever and use eval() in a compiled application to build your mCode interpreter, but the Matlab compiler doesn't allow that for obvious reasons.

这篇关于在Python,MATLAB等中使用eval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆