Search code examples
pythongetopt

Python module not callable when importing getopt


I am new to python and the getopt function. I am trying to import getopt, however I run into an error.

My code is literally just:

import getopt

and also tried

from getopt import *   /// from getopt import getopt

Output below:

python asdfasdf.py
ARGV      : []
Traceback (most recent call last):
  File "asdfasdf.py", line 1, in <module>
    import getopt
  File "/home/STUDENTS/~~/csc328/TCP/pyExample/getopt.py", line 12, in <module>
    'version=',
TypeError: 'module' object is not callable

My python is 2.6 something and this was implemented in 2.3 I believe.

edit: I'm using unix


Solution

  • you might be have getotp module in your code. When you refere python third party module, it try to import your module.

    Pleas remove getopt.py in your example or rename it.