2
class UserDict: 
    def __init__(self, dict=None):             
        self.data = {}                         
        if dict is not None: self.update(dict)

I created a file "abc.py" and put above in it.

>>> import abc
>>> d = abc.UserDict()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'UserDict'

1 Answer 1

7

Most certainly you are importing the Python abc module for abstract base classes instead of your own abc.py. Better choose a different name for your module.

Edit: Of course it is possible to have your own module with the same name as a built-in module and to import it. You have to make sure that your module is in the interpreter's working directory or set the Python path correctly. But it is much easier to avoid the name clash -- in particular in this case, where you presumably don't care about the module's name anyway.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, you're probably not importing the abc you think you are. print abc.__file__ to check.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.