Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Is there some sane way to allow Python to import from subfolders in projects that don't have a package? I have many Python programs that I implemented as Python files inside a directory, without a...
Question
python-3
#1: Initial revision
Subfolders for package-less module imports
Is there some sane way to allow Python to import from subfolders in projects that don't have a package? I have many Python programs that I implemented as Python files inside a directory, without a `setup.py` file or other packaging boilerplate. I don't `pip install` these. Simply doing `cd` into the directory, and running files with `python some_script.py` is much more convenient. The problem is when the program grows and I need modularize it. Python files can import other files in the same directory, but not in subdirectories. Alas, subdirectories are sometimes very useful. How do you get Python files to import files from other directories? Is creating a package unavoidable in this case?