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

后端 未结 5 1229
挽巷
挽巷 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:17

    Sounds like an import issue. Is there another module in the same directory named random? If so (and if you're on python2, which is obvious from print random_item) then it's importing that instead. Try not to shadow built-in names.

    You can test this with the following code:

    import random
    
    print random.__file__
    

    The actual random.py module from stdlib lives in path/to/python/lib/random.py. If yours is somewhere else, this will tell you where it is.

提交回复
热议问题