Tricky : ‘dict’ object is not callable

What you’ve run into is called “shadowing”. You’ve created an object in some namespace (either the global namespace of your module, or the local namespace of a function) that has the same name as a the builtin dict type. This prevents you from accessing the builtin dict in the usual way.

You can still get to it, with a bit more effort. The builtins (or __builtin__ in Python 2) module holds all the built in objects that are normally accessible directly. So, to make your empty dictionary, you could do the following:

import builtins

dict = whatever

newdic = builtins.dict()

But… It’s probably just a better idea to avoid using the name dict for your own objects.

Leave a Comment