473,413 Members | 1,727 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,413 software developers and data experts.

TypeError: 'module' object is not callable

All, I am trying to learn python. The below code is from a book example. I have researched the error:
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "bin/flips.py", line 4, in <module>
  3.     import random
  4.   File "/home/david/bin/random.py", line 10, in <module>
  5.     if random.random() < 0.5:
  6. TypeError: 'module' object is not callable

What I have found is that the code example (below) is referencing the class object (random) and not the function of the class. Does anyone know how to fix this and any additional knowledge of why it is happening would be great.

Code:
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import random
  5.  
  6. experiments, flips = 500, 16
  7.  
  8. #count = 0
  9. heads = [0] * (flips + 1)
  10.  
  11. # Perform each experiment.
  12.  
  13. for i in range(experiments):
  14.   count = 0
  15.   # Accumulate the number of heads.
  16.  
  17.   for j in range(len(heads)):
  18.     if random.random() < 0.5: count += 1
  19.   heads[count] += 1
  20.  
  21. # Print the numeric results.
  22.  
  23. print "heads:\n", heads, "\n"
  24.  
  25. # Print the histogram.
  26.  
  27. for j in range(flips + 1):
  28.   print "%2d " % j,
  29.   i = 0
  30.  
  31.   # print a "*" for each 10 occurrences.
  32.  
  33.   while i < heads[j]:
  34.     print "*",
  35.     i += 10
  36.  
  37.   print
Jun 6 '11 #1
2 1469
Sorry, folks. I finally found the issue. It was starring me straight in the face. I found that I had created a previous python program and used the same name as a python class/module, which I should not have done.
Jun 6 '11 #2
bvdet
2,851 Expert Mod 2GB
Good find David. Post again if you have any other issues.
Jun 7 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gary Wessle | last post by:
dear python users I am not sure why I am getting **************************************************************** Traceback (most recent call last): File "my.py", line 3, in ?...
10
by: Charles Russell | last post by:
Why does this work from the python prompt, but fail from a script? How does one make it work from a script? #! /usr/bin/python import glob # following line works from python prompt; why not in...
33
by: christophertidy | last post by:
Hi I am new to Python and have recieved this error message when trying to instantiate an object from a class from another file within the same directory and wondered what I have done wrong. I...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.