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 5846677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:36:38+00:00 2026-05-22T12:36:38+00:00

I am learning python and i am new bie. I am trying to use

  • 0

I am learning python and i am new bie.
I am trying to use functions with mysql and python and i ma getting errors

This is my script

import MySQLdb
def insert_values(cursor, values):
    #cursor = self.connection.cursor()
    cursor.executemany("""
        insert into pythontest (name1,name2,name3)
        values (%s, %s, %s)""", values)
    cursor.close()

db = MySQLdb.connect("localhost","root","root","python" )
cursor = db.cursor()

var1 = ['name1','name2','name3']
insert_values(cursor,var1)

db.close()

There may be many errors because i am learning

1)i don’t know how can i pass db
object in function or passing cusrsor
is ok. because i have to call that
function many times in for loop

2)is the syntax of values array ok to
go in database

ERRORS

File "mysql.py", line 10, in insert_values
    values (%s, %s, %s)""", values)
  File "build/bdist.linux-i686/egg/MySQLdb/cursors.py", line 216, in executemany
  File "build/bdist.linux-i686/egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
_mysql_exceptions.ProgrammingError: not enough arguments for format string
  • 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-22T12:36:38+00:00Added an answer on May 22, 2026 at 12:36 pm

    Here’s how I would write that (But untested):

    import MySQLdb
    
    def insert_values(db, values):
        cursor = db.cursor()
        try:
            try:
                cursor.execute("""
                insert into pythontest (name1,name2,name3)
                values (%s, %s, %s)""", *values)
            except:
                db.rollback()
                raise
            else:
                db.commit()
        finally:
            cursor.close()
    
    db = MySQLdb.connect("localhost","root","root","python" )
    
    vars = ('name1','name2','name3')
    insert_values(db, vars)
    
    db.close()
    

    The cursor starts a transaction, so you don’t want to re-use the same cursor for multiple updates unless they are part of an atomic transaction.

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

Sidebar

Related Questions

I'm new to this site, and new to Python. So I'm learning about Regular
i am new to python and learning it for my job functions. im following
I am learning Python and trying to figure out an efficient way to tokenize
I was just reading through Learning Python by Mark Lutz and came across this
I'm new to python(sqlalchemy), and I'm learning to build web site with pylons and
I'm considering learning a new language as an alternative to PHP. I'm considering Python
Here's the code from sys import argv script,from_file, to_file = argv open(to_file,'w').write(open(from_file).read()) I'm new
guys, I am rather new to python and learning it to build a gui
I am learning Python for a class now, and we just covered tuples as
I've been learning python for a while now with some success. I even managed

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.