Sheila
Posts: 21
Joined: Sat Jan 11, 2014 2:26 pm

Random module problems

Thu Jan 23, 2014 5:44 pm

I was trying to use some random module functions and something seems very wrong.
I ran a brief program to check the first bit before actually executing any random statements. and something wasn't right. Without going through the whole diagnosis, it seems that just doing the "import random" command the program prints out whatever it has previously printed before running the program. It even manages to do this after its been rebooted or turned off. It does it regardless of whether its being run from geany or a command line, or whether or not I write a new program.

If I put in
random.sample (1,2,3),1)
it says attribute doesn't exist
If I put in
random.random()
it says attribute not callable


Any clues, what is going on here or how I fix it?

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Random module problems

Thu Jan 23, 2014 7:13 pm

Have you got a file called random.py in your folder?

It sounds like you're importing that file rather than the standard python random module.
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Sheila
Posts: 21
Joined: Sat Jan 11, 2014 2:26 pm

Re: Random module problems

Thu Jan 23, 2014 8:05 pm

Thank you a million times!
Not only have you solved the problem, you stopped me having a nervous breakdown and saved the health service loads of money.

I'd started off calling the program random.py, thought that might be the problem and changed it. But it didn't occur to me that the new program was calling the old one instead of a module. I'd sort of forgot the old one was still in the directory once I'd changed the name. One of those situations where you've tried so many things you forget what you've done.

User avatar
elParaguayo
Posts: 1943
Joined: Wed May 16, 2012 12:46 pm
Location: London, UK

Re: Random module problems

Thu Jan 23, 2014 8:42 pm

Great, glad it's working.

If it's any consolation, it's a mistake we've all made before!
RPi Information Screen: plugin based system for displaying weather, travel information, football scores etc.

Return to “Python”