6

I've 2 files a.py and b.py

a.py

from b import *

#and then some lines of code

b.py

import random
red = random.randrange(1,257) / 256.0

#and then some lines of code

While running I get an error saying 'module' object has no attribute 'randrange'.

I dont know why this error is popping up because when I test it in some dummy file trying to print red = random.randrange(1,257) / 256.0 , it works. But not in this case.

Why is this error popping up?

2 Answers 2

20

You've a third file, random.py. Rename it.

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

2 Comments

I already knew this and deleted the random.py file but pyc file got remained. Hence was getting the error.Thanks.
This is plainly stupid. Why, oh why, are there languages forcing me to rename my files? :(
3

To confirm @ignacio 's answer you can run python -v <script>

This will list down all the importing modules and from where they are imported.

Comments

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.