I've created a new category called "decode" that's going to be the home of compiler (and other) detritus such as the python error:
TypeError: Error when calling the metaclass bases
For this one, the answer is that you probably named a python class the same thing as the module (i.e., the file) that it's in. You then imported the module and attempted to use it like a class. You did this because you, like me, were probably a Java programmer not that long ago :-). The way to fix it is to import the module.class instead of just the module. Or, for sanity's sake, change the name of the class or the module so that it's more obvious what's being imported.
I think we're all doing the world a favor by helping out the Oracle with a few hints when we run across these things and there isn't a good answer already documented.
Wow, thanks for this post. I also use Java and had exactly the experience you described. "The Oracle" helped too ;)
Posted by: Andrew VanderVeen | April 13, 2010 at 10:12 PM
Really helpful tip. Coming back to Python from Java as well and just came upon that mysterious error.
Posted by: Account Deleted | April 25, 2010 at 01:09 AM
And it turns out that there is another case in which this error is generated: where you thought you defined a class but it turns out that you said "def" instead of "class" but since functions can be nested inside of functions Python accepted the syntax so it took you twenty minutes to notice the problem. Which I wanted to mention just in case anyone else who ever types "def" instead of "class" winds up doing the same Google search that I just did. :-)
Posted by: Brandon Rhodes | November 08, 2010 at 01:58 PM
I've stopped to search Google more than once on this one, each time for the same brainfart:
1) Just go ahead and develop the class right in main.py until it's kinda working
2) Create a new file Source/MyNewHalfBakedClass.py and move the code into it
3) Add "from Source import MyNewHalfBakedClass.py"
4) Try running the bugs out... get that funky error... and then remember the magical:
5) Add "from MyNewHalfBakedClass import *" to the mystical file Source/__init__.py
No need to rename anything, and it's super-obvious (to me) that MyNewHalfBakedClass is in a file with that same name. HTH and FWIW
Posted by: Rob L | December 13, 2010 at 09:38 PM
@RobL - Step 5 ("import *") is really, really not a good idea in Python. Its one of the few instances where the language does not prevent you from shooting yourself in the foot.
Posted by: Derek Hohls | January 12, 2012 at 05:11 AM
Thank you for addressing my problem so succinctly. I'll bet you didn't even know that I had this problem.
Posted by: Ed Greenberg | April 03, 2012 at 06:24 PM