469,602 Members | 1,678 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

random.random - Interpreter works, Script doesn't?

Hello,
If I type the following code directly into the interpreter, it works. If I
run it from a script, it generates the following error. Can someone help?
Thanks!

------------------------

import random

for i in range(10):
x = random.random()
print x

------------------------

TypeError: 'module' object is not callable
Jul 18 '05 #1
5 1369
"Bill" <> wrote:
Hello,
If I type the following code directly into the interpreter, it works. If I
run it from a script, it generates the following error. Can someone help?
Thanks!

------------------------

import random

for i in range(10):
x = random.random()
print x

------------------------

TypeError: 'module' object is not callable


I'll wager money that your script actually says this:

import random

for i in range(10):
x = random()
print x

....which IS trying to call a module.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #2
Pay up :-) Cut and pasted from script:

import random

for i in range(10):
x = random.random()
print x

Other ideas? Thanks!
Bill

"Tim Roberts" <ti**@probo.com> wrote in message
news:vj********************************@4ax.com...
"Bill" <> wrote:
Hello,
If I type the following code directly into the interpreter, it works. If Irun it from a script, it generates the following error. Can someone help?
Thanks!

------------------------

import random

for i in range(10):
x = random.random()
print x

------------------------

TypeError: 'module' object is not callable


I'll wager money that your script actually says this:

import random

for i in range(10):
x = random()
print x

...which IS trying to call a module.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.

Jul 18 '05 #3
Bill wrote:
Pay up :-) Cut and pasted from script:

import random

for i in range(10):
x = random.random()
print x

Other ideas? Thanks!


You didn't name the above script random.py, did you :-)

You would then import the script itself, and the variable named random is
again bound to the script itself, i. e. a module.

When you clean up, also make sure that there is no random.pyc or random.pyo
left over in the script directory.

Peter

Jul 18 '05 #4
You didn't name the above script random.py, did you :-)

Peter

Bingo :o) Thanks! Bad habit, huh?
Jul 18 '05 #5

Peter> You didn't name the above script random.py, did you :-)

Bill> Bingo :o) Thanks! Bad habit, huh?

Very bad. Done often enough you will wind up with lots of bite marks on
your butt.

Skip

Jul 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by bhennon | last post: by
10 posts views Thread by BaBS | last post: by
16 posts views Thread by Neil Benn | last post: by
14 posts views Thread by DataSmash | last post: by
4 posts views Thread by tshad | last post: by
reply views Thread by Simon Eves | last post: by
16 posts views Thread by lawrence k | last post: by
1 post views Thread by John Boy | last post: by
reply views Thread by guiromero | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.