Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Elizabeth Ryan
1,151 PointsProblems running scripts that require using the random library.
I receive the following error when I try to run any script that imports the random library:
Traceback (most recent call last):
File "domsrandom.py", line 1, in <module>
import random
File "/home/treehouse/workspace/random.py", line 9, in <module>
word = random.choice(words)
AttributeError: module 'random' has no attribute 'choice'
I've run the scripts in other python shells and they've worked correctly. I've also had coworkers run my scripts in their Treehouse accounts and no one else is thrown this error. Can someone please help me figure out what is going on?
2 Answers
Jesse Pavlis
18,088 PointsHey Elizabeth,
It looks like you have a file named random.py in your working directory. If that is the case when you run import random it's importing your file, instead of the random library. Can you try renaming your file to something other than random.py.
Elizabeth Ryan
1,151 PointsThank you! Such an easy fix :)