Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Random Module problems in VSCode

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
enter image description here

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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…

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading