Robert Latest via Python-list <python-list@python.org> writes: > Because the main.py script needs to import the tables.py module from > backend, I put this at the top if main.py: > > sys.path.append('../..') > import jobwatch.backend.tables as tables > > My question is: Is this the way it should be done? It looks fishy. The > only alternative I could come up with is to put a symlink to tables.py > into the frontend directory, which also seems fishy.
Your fish-sense is working correctly. Both of those are hard-coding the path, when the Python import mechanism is designed so you don't do that. Instead, to run the package, first install the package. To install the package, use the Pip tool. This comes standard when you install Python 3. By installing your code, you make it available to be discovered by Python's normal import mechanism. So, choose how you want to install the package: * To install for normal use, ‘python3 -m pip install …’. * To install for use only by the current user, add the ‘--user’ option. * To install for use while also developing, add the ‘--editable’ option. See the ‘python3 -m pip --help’ document for details about what all that does. -- \ “Telling pious lies to trusting children is a form of abuse, | `\ plain and simple.” —Daniel Dennett, 2010-01-12 | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list