Hey, I'm new to Python and wondering about the following bit of code. It tells me that the module random has no attribute randint. I've looked at the documentation and such and I think I'm doing it correctly, but obviously something's wrong. Any ideas? Thanks!
import random
int1=random.randint(1, 6)
int2=random.randint(1, 6)
print "Die one was "+str(int1)
print "Die two was "+str(int2)
print "Your total was "+str(int1+int2)
Something tells me that you saved one of your programs as random.py. Avoid naming any of your programs with module names.
Python looks into the working directory first for imports. If it finds random.py (your homemade program) there, it doesn't look any further. What you really want is the random.py module file that is in the Lib directory that would be searched later in the PYTHONPATH.
So, if you have a random.py file in your working directory, rename it to something else to avoid this conflict.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417