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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • calvin dong
    New Member
    • Oct 2011
    • 8

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

    i am a beginner, i tried to have python generate a random integer from 0 to 10
    my code looks like this:

    import random
    number = random.randint( 0,10)
    print number

    i am using python 2.7
    it gives AttributeError: 'module' object has no attribute 'randint'

    please help, thank you very much.
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    My guess is that "random" is misspelled in the original code. We don't have the complete error message so there is no way to tell anything really.

    Comment

    • bvdet
      Recognized Expert Specialist
      • Oct 2006
      • 2851

      #3
      I'll take a guess. You have anther file named "random.py" on the Python path that is read before the random module is reached.

      Comment

      • dwblas
        Recognized Expert Contributor
        • May 2008
        • 626

        #4
        And we've all done that so I usually add "test" to any program names when testing a module, "random_test1.p y".

        Comment

        • calvin dong
          New Member
          • Oct 2011
          • 8

          #5
          Thanks bvdet and dwblas, in my python path there was another random.py file which was being read before the random module.

          Thank you all.

          Comment

          • calvin dong
            New Member
            • Oct 2011
            • 8

            #6
            I am sorry for this nonrelated post, but can someone kick fgjtydger out of the forum because i dont know how.

            Comment

            Working...