random module and VSCode have been giving me some trouble
import random
a = random.randint(5, 10)
print(a)
This is my code, and for some reason, it won't execute in VSCode, but it works just fine in powershell. Here is the error I have been getting in VSCode
However, when running this in the VSCode debugger, it works as intended, but after that it goes back to being annoying. How do I resolve this?
CodePudding user response:
Rename your file from random.py
to something else. Python is getting confused because the file name shadows the random
module.
BTW, this is what the circular import warning is about. You are importing random
, which is the file name. So, it imports the file you wrote. Whenever it imports the file, import random
is executed, which imports the file you wrote...