【发布时间】:2016-01-08 12:36:35
【问题描述】:
我想知道为什么我构建类的简单示例无法正常工作:
树形结构如下所示
class_project/
├── class_project
│ ├── __init__.py
│ └── classtheclass.py
└── tests
├── __init__.py
└── test.py
classtheclass.py 看起来像这样:
class ClassTheClass(object):
def __init__(self):
print "yeees"
test.py 看起来像这样:
from class_project.classtheclass import ClassTheClass
i = ClassTheClass()
而 init.py 为空
所以如果我在 shell 上执行
python test.py
它给了我
Traceback(最近一次调用最后一次):文件“test.py”,第 1 行,在 from class_project.classtheclass import ClassTheClass ImportError: No module named class_project.classtheclass
这有什么问题。在 Pycharm 中,这甚至可以工作......!
【问题讨论】:
-
你试过了吗:
from classtheclass import ClassTheClass? -
把test.py放到class_project里面(在tests后面),执行test.py就可以访问classtheclass了。
标签: python python-2.7