[Tutor] Code query..works in IDLE but not DrPython editor

Dave Kuhlman dkuhlman at rexx.com
Tue Jul 10 20:58:59 CEST 2007


On Tue, Jul 10, 2007 at 01:37:34PM -0400, Tony Noyeaux wrote:
> 
> Simple Random code.
>  
>  
> import randomprint random.choice(['Apple', 'Pear', 'Shrimp', 'Death', 'Life'])
>  
>  
> Works in IDLE gui, no problem. Gives me a random pick no problem.
>  
> When i changed to DrPython, to continue building parts of my code.. it won't take that code.
>  
> Gives me this error.
>  
> C:/Python/pythonw.exe -u  "C:/Python25/random.py"Traceback (most recent call last):  File "C:/Python25/random.py", line 1, in <module>    import random  File "C:\Python25\random.py", line 2, in <module>    print random.choice(['Apple', 'Pear', 'Shrimp', 'Death', 'Life'])AttributeError: 'module' object has no attribute 'choice'
>  
> ... not sure why one editor would work, and while the other
> won't?.. any suggestions.

Check the path and notice where random comes from under both
DrPython and Idle:

    import sys
    print sys.path
    import random
    print random

It might be that DrPython is finding a different module random from
that which Idle finds.

I was tripped by a similar error.  Idle and IPython both have my
bin directory on sys.path (I'm on Linux), while standard Python
does not.  IPython was finding one of my modules in the bin
directory, whereas standard Python found it under
lib/python2.5/site-packages.

Hope this helps.

Dave



-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman


More information about the Tutor mailing list