1

I have a recent problem with random module

I dont understand why is that? I showed the exact path that goes to random.py but it still didnt work. python3.4 64bit using pycharm 2016.2.2 First group is real error Second group relates to help(random) Sorry about confusion.

  File "C:/Users/blueg/Google Drive/Programming/Python/PycharmProjects/LearningPython/Random Module/random.py", line 1, in <module>
    import random     File "C:\Users\blueg\Google Drive\Programming\Python\PycharmProjects\LearningPython\Random Module\random.py", line 4, in <module>
    a = random.randint(1,6) AttributeError: 'module' object has no attribute 'randint'


Help on module random:
NAME random
FILE c:\users\blueg\google drive\programming\python\pycharmprojects\learningpython\random module\random.py
Doğuş
  • 1,887
  • 1
  • 16
  • 24

1 Answers1

1

you have called your module random.py and thus you're importing your own module: rename it it will work (and also delete the random.pyc associated file or python will use that one in turn)

(I sometimes think that naming one's module in german, french or other avoids conflicts :))

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • Thanks for reply sir.But it didnt help :( – Doğuş Aug 25 '16 at 22:09
  • also delete the `random.pyc` associated file – Jean-François Fabre Aug 25 '16 at 22:10
  • I found the file in __pycache__ and deleted it.(full name: random.cpython-34.pyc) After that code didnt work again. :( same error – Doğuş Aug 25 '16 at 22:14
  • You just deleted a python system file... Not a problem it will be regenerated. BTW I have an idea: rename it and *move it to another folder*. Run it from the command line (quit your editor) too. I'm 100% sure the problem is the name of your module. – Jean-François Fabre Aug 25 '16 at 22:15
  • i renamed "random.cpython-34.pyc" as "randomRENAMED.pyc" and put it in a file in desktop. From command prompt(as admin) i opened the file and : __ImportError: No module named site__. When i use idle,code works like magic.But with Pycharm editor,gives me an error. – Doğuş Aug 25 '16 at 22:23