英文:
Importing custom modules doesn't work (Python)
问题
import Activities
文件目录应为Activities,Play,Football,然后是函数mcball。
例如:这个不起作用
Activities.play.football.mcball()
Activities、play和football都是文件,mcball是函数。
没有其他组合起作用,我尝试过。
即使使用"from ... import ... as ..."也不起作用
帮助
不起作用,不知道为什么。
另外,一切都是自定义的。 "Activities" 不是我从互联网上获取的模块。
英文:
I'm getting straight to the point:
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
Doesn't work, no idea why.
Also, everything is custom. "Activities" is not a module i got from the internet.
答案1
得分: 2
如果您只导入顶层的Activities
包,内部模块将不会自动加载,除非Activities/__init__.py
文件为您导入它们。默认情况下,它不会执行任何操作,因此您需要导入实际的模块,使用以下代码:
import Activities.play.football
现在您应该能够成功调用Activities.play.football.mcball()
。
英文:
If you only import
the top-level Activities
package, the inner modules will not automatically be loaded, unless the Activities/__init__.py
file imports them for you. By default, it won't do anything, so you need to import the actual module, with:
import Activities.play.football
Now you should be able to call Activities.play.football.mcball()
successfully.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论