Guess?!? | 15 May 08:58

Random module error

Hello All,
 
I am importing module "random" and it is giving me this error below  AttributeError: 'module' object has no attribute 'randrange'
 
What could be the reason for this? When I chk API ..random module has a function randrange ......
 
>>> from TurtleWorld import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python25\swampy.1.1\TurtleWorld.py", line 1, in <module>
    from World import *
  File "C:\Python25\swampy.1.1\World.py", line 29, in <module>
    import random
  File "C:\Python25\random.py", line 4, in <module>
    i = random.randrange(10,50)
AttributeError: 'module' object has no attribute 'randrange'
>>>
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Kent Johnson | 15 May 14:00

Re: Random module error

On Thu, May 15, 2008 at 3:00 AM, Guess?!? <wtfwhoami <at> gmail.com> wrote:
> Hello All,
>
> I am importing module "random" and it is giving me this error
> below  AttributeError: 'module' object has no attribute 'randrange'

You have named your program random.py. The import finds your program
rather than the random module. Rename your program and delete the
associated .pyc file and it will work.

Kent
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Guess?!? | 15 May 21:48

Re: Random module error

Hello Kent,
 
I dont have any program with name random.py. I am using swampy API (http://allendowney.com/swampy/install.html)
As instructed by author, I do following steps
 
1> unzip/extract the folder into Python directory
2> go to the swampy directory
3> and invoke python command to start interpreter
4> as soon as I write from TurtleWorld import *
 
I get that error ..... I checked inside the folder ...there is no random.py and
i checked TurtleWorld.py ....there is only reference to standard module "random"
 
Thnks
G
 
 


 
On Thu, May 15, 2008 at 5:00 AM, Kent Johnson <kent37 <at> tds.net> wrote:
On Thu, May 15, 2008 at 3:00 AM, Guess?!? <wtfwhoami <at> gmail.com> wrote:
> Hello All,
>
> I am importing module "random" and it is giving me this error
> below  AttributeError: 'module' object has no attribute 'randrange'

You have named your program random.py. The import finds your program
rather than the random module. Rename your program and delete the
associated .pyc file and it will work.

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
christopher.henk | 15 May 22:18

Re: Random module error


Your original post showed this traceback:
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "C:\Python25\swampy.1.1\TurtleWorld.py", line 1, in <module>
   from World import *
 File "C:\Python25\swampy.1.1\World.py", line 29, in <module>
   import random
 File "C:\Python25\random.py", line 4, in <module>
   i = random.randrange(10,50)
AttributeError: 'module' object has no attribute 'randrange'

Which would suggest that the file World.py imported a file called random.py from the directory  C:\Python25\random.py
The random module that comes with python is typically stored in  the directory C:\Python25\Lib
and never contains the line:  i = random.randrange(10,50)

So I would look for a .py or .pyc file in your Python25 folder called random and remove it like Kent said.

Hope that works.

Chris



"Guess?!?" <wtfwhoami <at> gmail.com>
Sent by: tutor-bounces <at> python.org

05/15/2008 03:48 PM

To
"Kent Johnson" <kent37 <at> tds.net>
cc
tutor <at> python.org
Subject
Re: [Tutor] Random module error





Hello Kent,
 
I dont have any program with name random.py. I am using swampy API (http://allendowney.com/swampy/install.html)
As instructed by author, I do following steps
 
1> unzip/extract the folder into Python directory
2> go to the swampy directory
3> and invoke python command to start interpreter
4> as soon as I write from TurtleWorld import *
 
I get that error ..... I checked inside the folder ...there is no random.py and
i checked TurtleWorld.py ....there is only reference to standard module "random"
 
Thnks
G
 
 



On Thu, May 15, 2008 at 5:00 AM, Kent Johnson <kent37 <at> tds.net> wrote:
On Thu, May 15, 2008 at 3:00 AM, Guess?!? <wtfwhoami <at> gmail.com> wrote:
> Hello All,
>
> I am importing module "random" and it is giving me this error
> below  AttributeError: 'module' object has no attribute 'randrange'

You have named your program random.py. The import finds your program
rather than the random module. Rename your program and delete the
associated .pyc file and it will work.

Kent
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Guess?!? | 15 May 22:43

Re: Random module error

Got it fixed ...Thanks Kent and Chris. I might have created a prog and named it random and later deleted it but pyc was still sitting at the bottom ....I purged it and I am back on learning curve .... ...
 
~G

On Thu, May 15, 2008 at 1:18 PM, <christopher.henk <at> allisontransmission.com> wrote:

Your original post showed this traceback:
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "C:\Python25\swampy.1.1\TurtleWorld.py", line 1, in <module>
   from World import *
 File "C:\Python25\swampy.1.1\World.py", line 29, in <module>
   import random
 File "C:\Python25\random.py", line 4, in <module>
   i = random.randrange(10,50)
AttributeError: 'module' object has no attribute 'randrange'


Which would suggest that the file World.py imported a file called random.py from the directory  C:\Python25\random.py
The random module that comes with python is typically stored in  the directory C:\Python25\Lib
and never contains the line:  i = random.randrange(10,50)

So I would look for a .py or .pyc file in your Python25 folder called random and remove it like Kent said.

Hope that works.

Chris



"Guess?!?" <wtfwhoami <at> gmail.com>
Sent by: tutor-bounces <at> python.org

05/15/2008 03:48 PM

To
"Kent Johnson" <kent37 <at> tds.net>
cc
tutor <at> python.org
Subject
Re: [Tutor] Random module error





Hello Kent,
 
I dont have any program with name random.py. I am using swampy API (http://allendowney.com/swampy/install.html)
As instructed by author, I do following steps
 
1> unzip/extract the folder into Python directory
2> go to the swampy directory
3> and invoke python command to start interpreter
4> as soon as I write from TurtleWorld import *
 
I get that error ..... I checked inside the folder ...there is no random.py and
i checked TurtleWorld.py ....there is only reference to standard module "random"
 
Thnks
G
 
 



On Thu, May 15, 2008 at 5:00 AM, Kent Johnson <kent37 <at> tds.net> wrote:
On Thu, May 15, 2008 at 3:00 AM, Guess?!? <wtfwhoami <at> gmail.com> wrote:
> Hello All,
>
> I am importing module "random" and it is giving me this error
> below  AttributeError: 'module' object has no attribute 'randrange'

You have named your program random.py. The import finds your program
rather than the random module. Rename your program and delete the
associated .pyc file and it will work.

Kent
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Gmane