Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pycharm Import statement
#1
Hello -
Hoping this is the right forum.
I installed pycharm and started using it. I am running into an error when using the import statement. Can you please let me know what I need to do to resolve the below error. Thank you for your help in advance.

My code
import random
print(random.randint())
Error

Error:
"C:\Users\108167\PycharmProjects\Project 1\venv\Scripts\python.exe" "C:/Users/108167/PycharmProjects/Project 1/venv/random.py" Traceback (most recent call last): File "C:/Users/108167/PycharmProjects/Project 1/venv/random.py", line 1, in <module> import random File "C:\Users\108167\PycharmProjects\Project 1\venv\random.py", line 2, in <module> print(random.randint()) AttributeError: module 'random' has no attribute 'randint'
Reply
#2
don't name your file random.py. This way you shadow the built-in module with the same name.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cryptic Error with import statement Led_Zeppelin 2 2,586 Jan-11-2022, 01:13 PM
Last Post: Led_Zeppelin
  getting an import statement to work in my program barryjo 1 1,686 Dec-06-2021, 04:28 PM
Last Post: snippsat
  import statement in a virtual environment leodavinci1990 1 2,391 Mar-04-2021, 12:57 AM
Last Post: snippsat
  Creating Discord Bot: Unused import statement 'import discord EyeballCandy 0 3,569 Feb-02-2020, 10:53 PM
Last Post: EyeballCandy
  import statement query saisankalpj 4 2,816 Nov-01-2018, 09:08 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020