Import file from parent directory?

后端 未结 6 1981
悲哀的现实
悲哀的现实 2020-12-08 18:25

I have the following directory structure:

application
    tests
        main.py
    main.py

application/main.py contains some functions.

6条回答
  •  醉话见心
    2020-12-08 19:00

    You must add the application dir to your path:

    import sys
    sys.path.append("/path/to/dir")
    from app import object
    

    Or from shell:

    setenv PATH $PATH:"path/to/dir"
    

    In case you use windows: Adding variable to path in windows.

    Or from the command line:

    set PATH=%PATH%;C:\path\to\dir
    

提交回复
热议问题