【问题标题】:Why do I get an error from random.choice attribute but I don't use choice? [duplicate]为什么我从 random.choice 属性中得到一个错误,但我不使用选择? [复制]
【发布时间】:2021-02-26 13:30:07
【问题描述】:

为什么我收到关于选择属性的错误但我不使用选择?

这是我的python代码:

from random import randint
User, Computer = 0, randint(0,11)
# check process
while Computer != User:
   User = int(input('Enter Your number :'))
   print('Very good')
Error: 

in <module>
    print(random.choice(a))    
AttributeError: partially initialized module 'random' has no attribute 'choice' (most likely due to a circular import)

我不知道为什么会出现这个错误。

【问题讨论】:

  • 这工作得很好,没有任何错误。重置您的环境/电脑,然后重试...
  • print(random.choice(a)) - 您添加的代码中的这一行在哪里?当前添加的代码按预期工作。
  • @KrishnaChaurasia |是的,它是不规则的!因为在代码中我们没有这一行并且我们没有使用选择属性!我不知道我在做什么?????????
  • 您的工作目录或源文件目录中有 random.py 文件吗?如果您创建了一个,它可能与库之一冲突。重命名并重试。
  • @Malo 是的,我在这个代码目录中有 random.py 文件,我重命名了这个文件,现在程序可以工作了,我可以使用这个代码非常感谢,我不知道该怎么感谢你跨度>

标签: python python-3.x random


【解决方案1】:

您的工作目录或源文件目录中有 random.py 文件吗?如果您创建了一个,它可能与库之一冲突。重命名并重试。

【讨论】:

    猜你喜欢
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-15
    相关资源
    最近更新 更多