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

New to Python, can you please help with a question??

Hi I am new to Python. I am stuck on this question..... I know it is only simple but it just will not work for me and I have spent hours looking at the screen.. :(

below is some code. The first fuction is to simply return the average rating of the video and a count.... I thought I did this right as when I create a separate shell that links to the database it provides the average and the count. (number of ratings added to the database) But when I run the the test script it comes up with an error message saying

line 145, in test_average_rating
(avg, count) = util.average_rating(vid)
TypeError: 'NoneType' object is not iterable

What does this mean???

below is my code for that function and also another one.... I'm only very new to this so I am getting so frustrated with myself and am finding the university is not helping me much at all...
Expand|Select|Wrap|Line Numbers
  1. def average_rating(video_id):
  2.     """Return the average rating for this video and
  3.     the number of votes as a tuple (avg, count)"""
  4.  
  5.     con = connect()
  6.     cur = con.cursor()
  7.  
  8.     average = cur.execute("select AVG(rating), count(rating) from ratings")
  9.     for ratings in average:
  10.         print ratings
  11.  
  12. def add_rating(video_id, email, rating, comment):
  13.     """Add a rating for a given video and user email.
  14.     If the video or user doesn't exist, or if the rating is
  15.     outside of the range 1-5, raise an exception of
  16.     type WebappError with a message that can be
  17.     shown to the user.
  18.     """
  19.  
  20.     con = connect()
  21.     cur = conn.cursor()
  22.  
  23.     cur.execute("INSERT INTO ratings(video, email, rating, comment) VALUES ('?','?','?','?')")
  24.     conn.commit()
Apr 1 '10 #1
1 1553
bvdet
2,851 Expert Mod 2GB
Add a print statement after you assign the cursor query to variable average. I think you will find that average is not an object you can iterate on.
Expand|Select|Wrap|Line Numbers
  1. >>> av = 1
  2. >>> for obj in av:
  3. ...     print obj
  4. ...     
  5. Traceback (most recent call last):
  6.   File "<interactive input>", line 1, in ?
  7. TypeError: iteration over non-sequence
  8. >>> 
What fields are in the ratings table?
Apr 1 '10 #2

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

Similar topics

0
by: python-help-bounces | last post by:
Your message for python-help@python.org, the Python programming language assistance line, has been received and is being delivered. This automated response is sent to those of you new to...
112
by: mystilleef | last post by:
Hello, What is the Pythonic way of implementing getters and setters. I've heard people say the use of accessors is not Pythonic. But why? And what is the alternative? I refrain from using them...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...

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.