2
class UserDict:
def __init__(self, dict=None):
self.data = {}
if dict is not None: self.update(dict)
我創建了一個文件「abc.py」並放在上面。爲什麼這個Python不工作?簡單的OOP
>>> import abc
>>> d = abc.UserDict()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'UserDict'
是的,你可能沒有導入你認爲你的abc。 `打印abc .__ file__`來檢查。 – TryPyPy 2011-01-20 00:00:44