Search code examples
hy

importing module from current folder in 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

Solution

  • 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.