Python imports relative path

后端 未结 3 665
星月不相逢
星月不相逢 2021-02-04 05:10

I\'ve got a project where I would like to use some python classes located in other directories.

Example structure:

/dir
 +../subdirA
 +../subdirB
 +../my         


        
3条回答
  •  鱼传尺愫
    2021-02-04 05:52

    first add the relative paths to the pythonpath

    import os
    
    import sys
    
    cwd = os.getcwd()
    
    sys.path.append(cwd + '/../subdirA/')
    
    sys.path.append(cwd + '/../subdirB/')
    

    then import the modules.

提交回复
热议问题