导入自定义模块不起作用(Python)

e3bfsja2  于 2023-02-14  发布在  Python
关注(0)|答案(1)|浏览(173)

我就开门见山了:

import Activities
# File directory should be Activities,Play,Football then the function mcball.
# For example: This doesn't work
Activities.play.football.mcball()
# Activities, play, and football are files. mcball is the function.
# No other assortment works, I tried.
# Even "from ... Import ... as ..." doesn't work
#help

不管用,不知道为什么。
还有,一切都是定制的。“活动”不是我从网上得到的模块。

scyqe7ek

scyqe7ek1#

如果你只对顶层的Activities包执行import操作,内部的模块不会自动加载,除非Activities/__init__.py文件为你导入它们。默认情况下,它不会做任何事情,所以你需要导入实际的模块,使用:

import Activities.play.football

现在您应该能够成功调用Activities.play.football.mcball()了。

相关问题