可以将Python脚本导入另一个(Python)

发布于 2025-01-17 20:43:20 字数 184 浏览 2 评论 0原文

所以我有两个 python 脚本 - main.py 和 gui.py 在同一目录/文件夹中。但是当我尝试在 gui.py 中导入 main.py 时,它不起作用。当我尝试在 main.py 中导入 gui.py 时也是如此,

我尝试了这种方式

So I have two python scripts- main.py and gui.py in the same directory/folder. But when I try to import main.py in gui.py, it doesn't work. It's the same when I try to import gui.py in main.py

I tried it this way ????

from main import *

I saw several questions about similar things but nothing works. Please help and thanks in advance! I'm using Pycharm and Python 3.10

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔女人霸气范 2025-01-24 20:43:20

从 。 import main

然后,要调用属于 main.py 的函数,你应该这样做;

main.函数名()

from . import main

and then, to call a function that belongs to main.py, you should do;

main.function_name()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文