you are right on the lines you mentioned. Those are all working if i run it as a module which i do every time. This is somewhat unpleasant to me, especially while developing something and trying to test it quickly. I just want to be able to use same relative imports and run single file with `python3 test_main.py` for example. Running files as modules every time is tiring. This is my problem. I could not come up with a concrete solution idea yet i am thinking on it. Open to suggestions.
Thank you all for your help! On Fri, Nov 9, 2018 at 4:16 PM Steven D'Aprano <st...@pearwood.info> wrote: > On Fri, Nov 09, 2018 at 03:51:46PM -0800, danish bluecheese wrote: > > └── src > > ├── __init__.py > > ├── main.py > > └── test > > ├── __init__.py > > └── test_main.py > > > > assume the structure above. To be able to use relative imports with such > > fundamental structure either i can go for sys.path hacks or could run as > a > > module from one further level parent. > > I don't understand. From the top level of the package, running inside > either __init__ or main, you should be able to say: > > from . import test > from .test import test_main > > From the test subpackage, you should be able to say: > > from .. import main > > to get the src/main module, or > > from . import test_main > > to get the test/test_main module from the test/__init__ module. > > (Disclaimer: I have not actually run the above code to check that it > works, beyond testing that its not a SyntaxError.) > > What *precisely* is the problem you are trying to solve, and your > proposed solution? > > > > -- > Steve > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/