【问题标题】:Importing a python file another directory将python文件导入另一个目录
【发布时间】:2021-08-17 00:46:35
【问题描述】:

我正在尝试从 main.py 中导入 test.py 我怎么能做到这一点? main.py 和 test.py 都分配在应用程序文件夹中。 test.py 文件位于 app 文件夹中。

Directories
application folder
├── appFolder
│   └──test.py
└── main.py

Main.py 中的代码

from .TimeandClose import test```

【问题讨论】:

    标签: python-3.x file import directory python-import


    【解决方案1】:

    使用以下代码:
    from appFolder import test

    【讨论】:

    • 运行 test.py 但有没有办法在不运行脚本的情况下导入它
    猜你喜欢
    • 2021-09-23
    • 2017-09-12
    • 2023-03-20
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 2020-03-04
    相关资源
    最近更新 更多