Hacker News new | past | comments | ask | show | jobs | submit login

Relative imports are fuzzy if you don't dig deep, that said with a project scaffolded for you, it's rarely a headache (like testing in the old days), you can rapidly try various amount of dots.



I still haven't bothered to learn why relative imports require you to be in a package. It's a major headache if, like me, you do a lot of one-off work that doesn't warrant that project scaffolding.

Well, not a major headache. I can always revert to the py2 way: symlinks.


> It's a major headache if, like me, you do a lot of one-off work that doesn't warrant that project scaffolding.

Instead of creating "myproject.py", create a myproject folder with a __main__.py file. Run it as "python -m myproject".

Hardly any scaffolding and your code is in a package. It's one of the things I like about python, it's quite easy to move "up the ladder" scaffolding-wise if you need to.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: