有一个模块car.py
。初始化名称空间模块中的类
有发动机和轮胎,我想他们(他们的方法和属性)可访问的
car.engine.data
# and
car.tires.data
所以文件parts.py
看起来
class engineClass(object):
def __init__(self):
self.data = 'foo data 1'
class tiresClass(object):
def __init__(self):
self.data = 'foo data 2'
engine = engineClass()
tires = tiresClass()
现在import car
后我可以访问他们,因为我想 - car.engine.data
这是一个正确的事情做这项工作?
...而那会是什么任务? – 2011-06-12 04:18:38
你使用这些类是为了什么?用于分隔'type1'和'type2'的 – Blender 2011-06-12 04:19:39
。它们不同,但足够接近一个模块。 – Qiao 2011-06-12 04:21:52