从HY中的当前文件夹导入模块
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,以上产生
名称:名称“ printsomething”未定义
。问题是doit
是选择性导入的,因此名称printsomething
不绑定到整个模块。要获得选择性导入和整个模块,您需要或在python中
指出,这仍然会崩溃,因为
doit()采用0个位置参数,但给出了1个
。For me, the above produces
NameError: name 'printsomething' is not defined
. The problem is thatdoit
is imported selectively, so the nameprintsomething
is not bound to the whole module. To get both a selective import and the whole module, you needor in Python
Note that this will still crash, since
doit() takes 0 positional arguments but 1 was given
.