在 .py 文件中导入带有函数定义的 .hy 文件,并在从 python 从 .hy 调用函数后

Importing .hy file with function definition in .py file and after calling function from .hy from python

我的 .py 文件如下所示:

import hy
import example
foo2()

我的 .hy 文件看起来像:

(defn foo2 [] (+ 1 1))

.hy 文件与 .py 文件位于同一文件夹中。

如果我 运行 .py 文件我收到错误:

runfile('D:/del/hy2/untitled46.py', wdir='D:/del/hy2')
Reloaded modules: example
Traceback (most recent call last):

  File "<ipython-input-274-3982ada2f243>", line 1, in <module>
    runfile('D:/del/hy2/untitled46.py', wdir='D:/del/hy2')

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "D:/del/hy2/untitled46.py", line 3, in <module>
    foo2()

NameError: name 'foo2' is not defined


问题: 如果我想使用 Python 从 .py 文件调用 .hy 文件中定义的函数,如何更正我上面的代码?




顺便说一句,这很好用。

.py 文件中:

import hy
import example

.hy 文件中:

(print "Hello, World")

Python 无法在该上下文中解析名称 foo2。也许你的意思是 from example import foo2?我假设您的 .hy 文件是您导入的 example 模块。