如何导入包含文件的模块

use*_*165 0 python module

我已经安装了自己创建的自定义模块用于学习.如果我做

from my_first_module import test
test.thisprintssomething()
Run Code Online (Sandbox Code Playgroud)

该功能将起作用,但如果我这样做

import my_first_module
test.thisprintssomething()
Run Code Online (Sandbox Code Playgroud)

Python吐出,NameError:名称'test'未定义.如何在不使用"from"的情况下导入?

编辑:

我自己修好了.我忘了在my_first_module模块中的init .py中添加一个"import test"行.

ava*_*sal 6

因为你是导入my_first_module 你必须告诉代码,test属于my_first_module

import my_first_module

my_first_module.test.thisprintssomething()
Run Code Online (Sandbox Code Playgroud)

有关更多说明,您可以查看导入Python模块