如何在狮身人面像中包含模块

时间:2018-07-17 08:04:03

标签: python documentation python-sphinx

一个星期以来,我一直在寻找这个问题的答案。 希望你能帮助我:

我正在使用Sphinx进行文档记录,这是我的项目结构:

axios.post(`sms/${id}`, {params: {id: `${id}`}, _method: 'delete'})

在我的main.py内部

-folder
    __init__
    -main_tool_folder
        __init__
        main.py
        -docs_folder
    -modulefolder
        __init__
        fileIwanttodocument     

代码有效

在谈到Sphinx时,它会失败(在我执行导入的那一行上给出了错误)

在我的conf.py中 我用

sys.path.append('../')
from modulefolder.fileIwanttodocument import functionIneed

和在code.rst

sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(1, os.path.abspath('../../'))

如何包含fileIwanttodocument.py? 到目前为止,我发现的唯一方法是将其复制到main_tool_folder中,这违背了创建模块的目的

1 个答案:

答案 0 :(得分:0)

我自己解决了! 在conf.py之前

sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(1, os.path.abspath('../../'))

我有

sys.path.insert(0, os.path.dirname(os.getcwd()))

导致问题的原因。

显然我的做法是正确的!