Search code examples
pythonimportorganization

python import (project organization)


I am working on a python project and have generated tons of python scripts. I would like to put them in different directories for organization. My question is how can I import scripts form parent directories.

I want to be able to do

import ../utl/server.py

How can I achieve this, thanks in advance.


Solution

  • Do this as:

    from ..utl import server
    

    However, note that that kind of relative import works only in certain situations. See the documentation for more details).