Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建python模块_Python_Module - Fatal编程技术网

创建python模块

创建python模块,python,module,Python,Module,我创建了两个文件:test.py和test1234.py test.py包含: import test1234 t = test1234.test() class test(): def __init__(self): test1234.py包含: import test1234 t = test1234.test() class test(): def __init__(self): 当放在同一目录中时,python test.py运行时不会出错 但是,如果我创建一个目

我创建了两个文件:test.py和test1234.py

test.py包含:

import test1234
t = test1234.test()
class test():
    def __init__(self):
test1234.py包含:

import test1234
t = test1234.test()
class test():
    def __init__(self):
当放在同一目录中时,
python test.py
运行时不会出错

但是,如果我创建一个目录test1234,并将test1234.py和一个空白的init.py放在这个目录中,
python test.py
会给出错误:

AttributeError:“模块”对象没有属性“测试”


要使test.py能够在test1234.py中看到
test
类,我需要做什么?

您必须通过包导入它,或者将它放入
\uu init\uuuuuuuuuu.py

import test1234.test1234
t = test1234.test1234.test()

具体来说,在
\uuu init\uuuu.py
中放什么?我只希望在
test.py
中有
import test1234
。不过,我知道你可以在
\uuuu init\uuuuuuuuuuuuuuuuuy
中从test1234导入测试
;考虑重命名包还是子模块。我的问题还不够清楚吗?我不理解python导入是如何工作的,这是不能接受的吗?:)