【问题标题】:TypeError when importing a module导入模块时出现 TypeError
【发布时间】:2020-08-02 09:01:31
【问题描述】:

我是 Python 新手,我正在学习包。我正在尝试使用 random 模块,但出现 TypeError: 'module' object is not callable 错误。我的代码是:

import random

for i in range(3):
    print(random.random())

谁能告诉我为什么会这样?

问候

【问题讨论】:

标签: python module package typeerror


【解决方案1】:

您的文件名称是什么?如果您将文件命名为 random.py,您的脚本将不会运行。

Why do I get a TypeError: 'module' object is not callable when trying to import the random module?

我刚刚在 test.py 文件中测试了与您完全相同的代码,它没有问题。

【讨论】:

  • 我确实将我的文件命名为 random.py 。非常感谢。
  • @JuanFelipeContreras 没问题!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-14
  • 2021-10-24
  • 2020-05-13
  • 1970-01-01
  • 2022-11-30
  • 1970-01-01
相关资源
最近更新 更多