我创建了两个文件:test.py和test1234.py
test.py包含:
import test1234
t = test1234.test()
Run Code Online (Sandbox Code Playgroud)
test1234.py包含:
class test():
def __init__(self):
Run Code Online (Sandbox Code Playgroud)
当放在同一目录中时,python test.py运行没有错误.
但是,如果我创建一个目录test1234并将test1234.py和一个空的init .py放在此目录中,则会python test.py出现错误:
AttributeError:'module'对象没有属性'test'
我需要做什么才能让test.py能够test在test1234.py中查看该类?
您必须通过包导入它,或者将其放入__init__.py.
import test1234.test1234
t = test1234.test1234.test()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4136 次 |
| 最近记录: |