【问题标题】:Why am I getting this randint() error in python 3?为什么我在 python 3 中得到这个 randint() 错误?
【发布时间】:2014-11-15 01:50:09
【问题描述】:

我的解释器一直指向以下错误:

numshapes= random.randint(4, 9)

错误是:

Traceback (most recent call last):

  File "D:\current\robotics\project\AbstractAutomatica.py", line 361, in <module>

AttributeError: 'builtin_function_or_method' object has no attribute 'randint'

在我随机导入的文件开头:

import random

【问题讨论】:

  • 能否请您显示周围的代码?
  • 也许您在代码中的某处覆盖了名称 random?
  • 报错前大概有380行代码,但都是函数。
  • 尝试将numshapes = random.randint(4, 9) 行粘贴到import random 语句之后的一行。错误也会在那里抛出吗?
  • 你能列出你所有的全局变量吗?

标签: python-3.x random attributeerror


【解决方案1】:

我遇到了同样的问题,原因很简单:

from pylab import *

导入后随机。 pylab random 已覆盖 random 模块。

【讨论】:

    猜你喜欢
    • 2016-11-25
    • 2017-09-18
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-31
    相关资源
    最近更新 更多