簡體   English   中英

Importing.hy 文件與 function 定義在 .py 文件中並在從 python 調用 function from.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 文件中定義的.hy ,如何更正上面的代碼?




順便說一句,這很好用。

.py文件中:

import hy
import example

.hy文件中:

(print "Hello, World")

Python 在該上下文中無法解析名稱foo2 也許您的意思是from example import foo2 我假設您的.hy文件是您導入的example模塊。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM