我知道如何将hy
模块导入 python。我所要做的就是创建一个something.hy
包含hy
代码的文件,然后执行以下操作...
import hy
import something
something.func('args') # assumes there is an hy function called `func`
但是,我无法弄清楚如何在 python 中评估包含hy
代码的字符串。例如 ...
hycode = '(print "it works!")'
hy.SOMEHOW_EVALUATE(hycode)
# I'd like this to cause the string `it works!` to print out.
或者这个例子......
hycode = '(+ 39 3)'
result = hy.SOMEHOW_EVALUATE(hycode)
# I'd like result to now contain `42`
在 python 中使用时hy
,有没有办法以这种方式评估字符串?