-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...

6
  • Did you name one of your files random.py? Commented Jul 17, 2020 at 10:56
  • 1
    One of your files is called random.py, so Python imports it instead of the standard module Commented Jul 17, 2020 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? Commented Jul 17, 2020 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" Commented Jul 17, 2020 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'. Commented Jul 17, 2020 at 13:21

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

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'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.