'module' object has no attribute 'choice' - trying to use random.choice

后端 未结 5 1204
挽巷
挽巷 2020-12-31 00:48

Could someone please tell me what I may be doing wrong. I keep getting this message when I run my python code:

import random

foo = [\'a\', \'b\', \'c\', \         


        
5条回答
  •  有刺的猬
    2020-12-31 01:00

    I also got this error by naming a method random like this:

    import random
    
    def random():
    
      foo = ['a', 'b', 'c', 'd', 'e']
    
      random_item = random.choice(foo)
    
      print random_item
    
    random()
    

    It's not your case (naming a file random.py) but for others that search about this error and may make this mistake.

提交回复
热议问题