Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6900023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:29:42+00:00 2026-05-27T07:29:42+00:00

This code works fine when the cur.execute() and db.commit() lines are commented out; i.e.

  • 0

This code works fine when the cur.execute() and db.commit() lines are commented out; i.e. if all I do is print the query, this program runs for n number of rows. The problem seems to occur here:

player_categories_statistics = cur.fetchone()
player_id = player_categories_statistics[0]

When I try to insert the result, I get:

Traceback (most recent call last):
  File "test2.py", line 72, in <module>
    meat = meatgrind(league_name, categories_measurement_statistics)
  File "test2.py", line 32, in meatgrind
    player_id = int(player_categories_statistics[0])
TypeError: 'NoneType' object is not subscriptable

The code:

import sys 
import MySQLdb
import string 

db = MySQLdb.connect()
cur = db.cursor('localhost','me',XXXXX,'testdb')


def meatgrind(league_name,categories_measurement_statistics):
# a varied range of different categories can be used 

    # 1. list categories
    categories = []
    categories_string = "player_id"
    categories_string_newtable = "meatgrinded_player_id, player_id"
    for category in categories_measurement_statistics:
        categories_string += ", " + category[0]
        categories_string_newtable += ", " + category[0]


    # 2. get players and statistics
    query = "SELECT %s FROM players" % (categories_string)
    cur.execute("%s" % (query))
    # rowcount = int(cur.rowcount)
    rowcount = 2 #hard-coded for debugging

    # 3. meatgrind one player at a time
    meatgrinded_player_id = 1
    for i in range(rowcount):
        player_categories_statistics = cur.fetchone()
        player_id = player_categories_statistics[0]

        #4. grind a category statistic
        meatgrindings_string = "%d, %d" % (meatgrinded_player_id, player_id)

        index = 1
        for category in categories_measurement_statistics:

            # SOME MATH HERE resulting in player_meatgrindings

            meatgrindings_string += ", %0.4f" % player_meatgrindings



query = """INSERT INTO sometable (%s) VALUES (%s)""" % (categories_string_newtable, meatgrindings_string)
cur.execute("%s" % (query))
db.commit()

meatgrinded_player_id += 1


league_name = 'test'
categories_measurement_statistics = (('H', 156.3, 19.643093216474604), ('HR', 21.3, 9.003147597738618), ('SB', 13.25, 16.041179646286754))

meat = meatgrind(league_name, categories_measurement_statistics)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:29:43+00:00Added an answer on May 27, 2026 at 7:29 am

    The reason for your error is:

    player_categories_statistics = cur.fetchone()
    

    This sets player_categories_statistics to None. None[0] raises the exception.

    The only reason this would happen is your query returns no rows, which means your table is empty. Your table is most likely is empty because you never put any rows in it, or less likely you removed them somehow.

    I culprit may be the following, you are inserting into sometable and selecting from players:

    INSERT INTO sometable (%s) VALUES (%s)
    

    vs

    SELECT %s FROM players
    

    The only reason this is possible is because your forcing it to loop even if nothing was returned with the line:

    rowcount = 2 #hard-coded for debugging
    

    Additional Info:

    Here’s a working query I ran on an sqlite3 database with a single table with a single row with nearly identical statements as yours, just to show that yours should be working if the data is indeed there.

    query = "SELECT %s FROM customer" % 'first_name, last_name'
    
    row = c.execute("%s" % (query)).fetchone()
    
    row
    Out[28]: (u'Derek', u'Litz')
    

    Here’s another working query on a sqlite3 database with another table and no rows.

    query = "SELECT %s FROM customer2" % 'first_name, last_name'
    
    print c.execute("%s" % (query)).fetchone()
    None
    

    As you can see, identical to the behavior above.

    Also make sure rowcount works they way you want with your DB. It doesn’t with sqlite3, for example. See rowcount spec in http://www.python.org/dev/peps/pep-0249/#cursor_objects and consulte MySQLdb docs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

web page : http://sideradesign.com/eco-art/gallery/ This code works fine in all brwosers except IE8 (haven't
This code works fine: Query query = parser.Parse(expression); IFullTextSession session = Search.CreateFullTextSession(this.Session); IFullTextQuery fullTextQuery
Now All of this code works fine in Firfox but in IE the divs
This code works fine: $result = $client->__call(optionalInfo, array( new SoapParam(..., client), new SoapParam(..., add_code))
this code works fine until I start scrolling: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
This code works fine to find an available room within certain date, but it
This code works fine in C#: Expression.Lambda(LambdaBody); But none of the methods for building
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
I have this piece of code that works fine in subsonic 2.2, I migrated
I have this code, which works fine, but I would like to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.