[Tutor] Problems importing random on linux

adam at monkeez.org adam at monkeez.org
Tue Apr 27 02:21:53 EDT 2004


> [Adam]
>> I use a linux machine and win machine at work. My win machine
>> has no problem importing random and then using the randint(x,y)
>> module.  However, when I try and do this on my linux debian
>> machine, I get:
>>
>> adam at debian:~/python$ ./autoguess.py
>> Traceback (most recent call last):
>>  File "./autoguess.py", line 49, in ?
>>    generatenumber()
>>  File "./autoguess.py", line 6, in generatenumber
>>    target = random.randint(0,100)
>> AttributeError: 'module' object has no attribute 'randint'
>>
>> from the code:
>> import random
>>
>> def generatenumber():
>>    target = random.randint(0,100)
>>
>> What is going on here? I've tried the same small piece of code:
>> import random
>> target = random.randing(0,100)
>> at the interpreter and it works, but if I try this as an
>> application in a file, it fails.
>>
>> Any ideas ?
>
> Do you perhaps have a file named random.py in the same directory as
> autoguess.py?  To me, it sounds like the random module imported is
> different from the standard library module.
>
> Peace,
>   Kalle
> --

Thanks Kalle - that was exactly it - I've also removed the .pyc files and
it works fine now. That's one mistake I'll try to avoid again.

Thanks once again.

adam



More information about the Tutor mailing list