search

Home  >  Q&A  >  body text

django - python 2 layer folder import

Account(folder)

alimns.py (这里是要导入的)

mns_python(folder)

mns(文件夹)
    account.py(被导入的)

How to import this

typechotypecho2746 days ago956

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-07-05 10:29:14

    First we have to jump to the same level as the Account file
    import sys
    sys.path.append('..')
    Call the sys module, sys.path returns the search path of the module, and use the PYTHONPATH environment variable during initialization Value
    .. Jump to the upper level directory
    Then you can directly import account.py from mns_python.mns
    Note: mns_python needs to have the __init__.py file (I got stuck here - I hope everyone can take this as a warning) )

    reply
    0
  • Cancelreply