473,382 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 1471
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to...
10
by: BaBS | last post by:
I've a problem whith my python script, i chmod'ed it to +x, addes the line : #!/usr/bin/python2.3 and i verified that /usr/bin/python2.3 exists but i've something like : bad interpreter: No such...
16
by: Neil Benn | last post by:
Hello, I'm looking at a small app which would need a very quick startup time for the Python interpreter. It doesn't do much (copying and caching of files, no GUI) but I need the Python...
6
by: Olly | last post by:
I've found a basic script, however I also need to add alt and title attributes as well, how would I go about doing this? Here's the script I found: Thanks <script language="JavaScript"> <!--...
14
by: DataSmash | last post by:
Hi, When I import the random module at the python interpreter, it works fine: >>> import random >>> x = random.randint(1,55) >>> print x 14 >>> BUT, when I put the same code in a python...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
0
by: Simon Eves | last post by:
I am trying to write a Python module to embed the functionality of Maya (the 3D modelling and animation application from Autodesk, formerly Alias) for doing scripted scene manipulation and...
16
by: lawrence k | last post by:
I've never before written a PHP script to run on my home Ubuntu machine (though I've written dozens of PHP cron jobs for my web server), so I thought I'd start off with a very simple test: ...
1
by: John Boy | last post by:
First post and very much a newbie to Python. Have 2.5 on Linux (GG). I think I have set up PYTHONPATH correctly in that I can import a module apply_bp and it complains about line 20 in apply_bp...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.