Python Forum

Full Version: (TypeError: 'module' object is not callable) for getopt Module
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm fairly new to python, and I have been trying to use the "getopt" module working in my script without success.

I troubleshoot, I removed all other code from my script and just worked with the code shown below. Working in the interactive shell, I have no problems getting output.


SCRIPT
--------------------------------------------------------
#!/usr/bin/python

import getopt

print getopt.getopt(['-a', '-bval', '-c', 'val'], 'ab:c:')
---------------
OUTPUT:
Traceback (most recent call last):
File "./test-getopt.py", line 3, in <module>
import getopt
File "/home/nnevarez/HTB/SCRIPTS/getopt.py", line 23, in <module>
#
TypeError: 'module' object is not callable





INTERACTIVE
-------------------------------------------------------
>>> import getopt
>>>
>>>
>>> print getopt.getopt(['-a', '-bval', '-c', 'val'], 'ab:c:')
([('-a', ''), ('-b', 'val'), ('-c', 'val')], [])
>>>
-------------------------------------------------------
You have a file called "getopt.py". This is interfering with the module "getopt.py". Rename your file to something else.
Thanks a lot! That did the trick.