Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - 'module' object has no attribute 'randrange'

Tags:

python

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?

like image 820
PythonEnthusiast Avatar asked Aug 25 '26 09:08

PythonEnthusiast


2 Answers

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

like image 95
Ignacio Vazquez-Abrams Avatar answered Aug 26 '26 23:08

Ignacio Vazquez-Abrams


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.

like image 44
Arovit Avatar answered Aug 26 '26 21:08

Arovit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!