Hacker News new | ask | show | jobs
by abhisuri97 1797 days ago
Despite using python for the past 4 years, it still takes me several tries to set up packages and imports correctly when I make them myself. Honestly, I wish that python had an import system similar to JS (where you can just say “I want this file” <insert path to file> and specify the exports yourself). For me, it just feels more intuitive and less “magic”-like when dealing with custom scripts you want to import.
1 comments

I have seen way too many `ModuleNotFoundError`s. It is moderately infuriating when the two files are in the same directory and python can't find the module.

Honestly that error is misnamed. It should be `ModuleImportRefusedError`.

And the frustration caused by getting PyTest to work in a project is likely responsible for a large percentage of the untested python projects in the world...

I’ve not had either of these issues. Maybe a detail left out?
the first occurs if you haven't created __init__.py.

the second occurs if you want your test files outside of the package directory (e.g., project/src/foo_app/foo.py, project/test/test_foo.py)