从HY中的当前文件夹导入模块

发布于 2025-01-30 13:55:04 字数 362 浏览 2 评论 0原文

HY版本1.0A4+199.G22021C56的导入已更改? 我正在尝试从同一文件夹(或CWD)导入文件,但是

即使我将当前路径附加到sys.path,也

没有名为“ themameofthefile'的模块:也没有模块。这就是您可以重现它的方式。

#!/bin/sh
echo "(defn doit[] (print \"something\"))" > printsomething.hy

echo "(import printsomething [doit])" > callit.hy
echo "(doit printsomething)" >> callit.hy

hy callit.hy

Has import changed in Hy version 1.0a4+199.g22021c56?
I'm trying to import a file from the same folder (or cwd), but I get ModuleNotFoundError: No module named 'thenameofthefile'

Even if I append current path to sys.path.

This is how you can reproduce it.

#!/bin/sh
echo "(defn doit[] (print \"something\"))" > printsomething.hy

echo "(import printsomething [doit])" > callit.hy
echo "(doit printsomething)" >> callit.hy

hy callit.hy

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞琼窗梦回ˉ 2025-02-06 13:55:04

对我来说,以上产生名称:名称“ printsomething”未定义。问题是doit是选择性导入的,因此名称printsomething不绑定到整个模块。要获得选择性导入和整个模块,您需要

(import  printsomething [doit]  printsomething)

或在python中

from printsomething import doit
import printsomething

指出,这仍然会崩溃,因为doit()采用0个位置参数,但给出了1个

For me, the above produces NameError: name 'printsomething' is not defined. The problem is that doit is imported selectively, so the name printsomething is not bound to the whole module. To get both a selective import and the whole module, you need

(import  printsomething [doit]  printsomething)

or in Python

from printsomething import doit
import printsomething

Note that this will still crash, since doit() takes 0 positional arguments but 1 was given.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文