Python package import from parent directory

后端 未结 4 655
情深已故
情深已故 2020-12-29 02:22

I\'ve the following source code structure

/testapp/
/testapp/__init__.py
/testapp/testmsg.py
/testapp/sub/
/testapp/sub/__init__.py
/testapp/sub/testprinter.         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-29 03:03

    For people who still have this same problem. This is how I solve mine:

    import unittest 
    import sys
    import os
    
    sys.path.append(os.getcwd() + '/..')
    
    from my_module.calc import *
    

提交回复
热议问题