0
import random 
x=[1,3,6,7] 
print(random.choice(x))

while running program....

File "c:\Users\Slug\Desktop\100 days\day 4\random.py", line 1, in <module>
    import random
  File "c:\Users\Slug\Desktop\100 days\day 4\random.py", line 3, in <module>
    print(random.choice(x))
AttributeError: partially initialized module 'random' has no attribute 'choice' (most likely due to a circular import) 
Mustafa Aydın
  • 17,645
  • 4
  • 15
  • 38
  • 2
    are you naming your file the same name as the module? – gold_cy Apr 29 '21 at 11:35
  • Are you running this inside of a package you're creating or as a standalone script? If you're writing a package, please share what the directory looks like and the import statements of relevant files :) – gmdev Apr 29 '21 at 11:36
  • If you look at the traceback more cIosely you will see that the problem is that line 1 of `c:\Users\Slug\Desktop\100 days\day 4\random.py`(your program) is trying to import module `random`, in other words, itself. Call your program something else. – BoarGules Apr 29 '21 at 11:42
  • @gold_cy this was the problem for me. Thanks! – Scholar Oct 28 '21 at 10:09

1 Answers1

2

First of all , Your question code is NOT in standard format, I just want to remind you to avoid the same problem next time. Steps to fix the problem. Your problem is obviously : Your python name is as same as the module's name. You will need to rename you python file "random.py" into another name like "r1balabala.py" or any names you would like use, as long as it is different from the module name.

TO Conclusion: In your further learning with python, you should always make your file name specific and different with the module that you need to import. Reason: the python interceptor could not determine which file you need to import.(Your local .py script or the module!)

Best wish