Import file from parent directory?

后端 未结 6 1968
悲哀的现实
悲哀的现实 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 18:56

    To import a file in a different subdirectory of the parent directory, try something like this:

    sys.path.append(os.path.abspath('../other_sub_dir'))
    import filename_without_py_extension
    

    Edit: Missing closing bracket.

提交回复
热议问题