note to self and world: stupid ”TypeError: ‘module’ object is not callable” error in python
december 7, 2008
Hello world. I decided to take up my crappy python knowleage recently, and my second script was a small password generator. In the script I had the following:
import random print(random.randint(0, 16))
It failed miserably with a ”TypeError: ‘module’ object is not callable”, even though it was perfectly valid code. It worked fine in the interactive python shell, but not when running the file. After a bit of googling i found that python prioritizes the current folder files before the regular modules, and my file was called random.py. Thus my script included itself and tried to access the random object – failing miserably.
So in todays life lesson we learned to not use filenames that are also present in the python stdlib.