« Monitors in spaaaaaace.... | Main | Using Furl with Aardvark? »

March 30, 2005


Andrew VanderVeen

Wow, thanks for this post. I also use Java and had exactly the experience you described. "The Oracle" helped too ;)

Account Deleted

Really helpful tip. Coming back to Python from Java as well and just came upon that mysterious error.

Brandon Rhodes

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. :-)

Rob L

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

Derek Hohls

@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.

Ed Greenberg

Thank you for addressing my problem so succinctly. I'll bet you didn't even know that I had this problem.

The comments to this entry are closed.

My Photo

Become a Fan

My Other Accounts

Facebook Google Plus Skype Twitter