-1

i've been going through some tutorials and have been actively taking notes whilst watching the videos and copying the code. Which has resulted in having multiple python files in my pycharm projects.

I have noticed that when i reach a certain number of files the terminal returns back errors but when the code is run a new project folder it runs perfectly fine.

Not sure why that is, has anyone got any ideas? Also should i be creating multiple python files when learning?

This is an example of an error:

Code:

import random

value = random.randint(1, 6)
print(value)

error:

AttributeError: module 'random' has no attribute 'randint'

But when run in a new project it works...

iqram
  • 15
  • 6
  • Did you name one of your files random.py? – Gino Mempin Jul 17 '20 at 10:56
  • 1
    One of your files is called `random.py`, so Python imports it instead of the standard module – ForceBru Jul 17 '20 at 10:56
  • How many files do you have, because you should have a lot of files, because I have used about a hundred files in pycharm with a lot of code in them, and have not had a problem? – topsoftwarepro Jul 17 '20 at 10:56
  • 1
    Does this answer your question? [Importing installed package from script raises "AttributeError: module has no attribute" or "ImportError: cannot import name"](https://stackoverflow.com/questions/36250353/importing-installed-package-from-script-raises-attributeerror-module-has-no-at) – quamrana Jul 17 '20 at 11:06
  • I made a newbie error and named my file random. Thanks for the help everyone else. Not sure why it was down voted... The last time it didnt work was probably because i called my file 'json'. – iqram Jul 17 '20 at 13:21
  • Does this answer your question? [random.randint error](https://stackoverflow.com/questions/4178648/random-randint-error) – Gino Mempin Jul 18 '20 at 11:18

1 Answers1

0

Do you have another script called random? It might be trying to import .randint() from there.

0x4A42
  • 60
  • 7
  • I made a newbie error and named my file random. Thanks for the help everyone else. Not sure why it was down voted... The last time it didnt work was probably because i called my file 'json'. – iqram Jul 17 '20 at 13:19