I have two files: in one of them (named myrandom
) I have defined a function called spinner
that would choose a random number from 1 to 6 and would return its value. In the second file, named main
, I have imported the first one (as a module) and have also called the spinner
function.
This is the code of the file myrandom
:
def spinner():
import random
val = random.choice([1, 2, 3, 4, 5, 6])
return val
And this is the code of main
:
import myrandom
x = spinner()
print(x)
My problem is that when I run main
, I get the following error message: "NameError: name spinner() is not defined". I don't know why I'm getting this error, since I have other files and modules with similar characteristics that run without problems.
Any idea?