Python 模块在导入 getopt 时不可调用

Python module not callable when importing getopt

我是 python 和 getopt 函数的新手。我正在尝试导入 getopt,但是我 运行 出错了。

我的代码实际上只是:

import getopt

也尝试过

from getopt import *   /// from getopt import getopt

输出如下:

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

我的 python 是 2.6,我相信这是在 2.3 中实现的。

编辑:我使用的是 unix

您的代码中可能有 getotp 模块。当您引用 python 第三方模块时,它会尝试导入您的模块。

请删除示例中的 getopt.py 或重命名。