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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:45:04+00:00 2026-05-14T06:45:04+00:00

I use this bit of code to feed some data i have parsed from

  • 0

I use this bit of code to feed some data i have parsed from a web page to a mysql database

c=db.cursor()
c.executemany(
"""INSERT INTO data (SID, Time, Value1, Level1, Value2, Level2, Value3, Level3, Value4, Level4, Value5, Level5, ObsDate)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
clean_data
)

The parsed data looks like this (there are several hundred such lines)

clean_data = [(161,00:00:00,8.19,1,4.46,4,7.87,4,6.54,null,4.45,6,2010-04-12),(162,00:00:00,7.55,1,9.52,1,1.90,1,4.76,null,0.14,1,2010-04-12),(164,00:00:00,8.01,1,8.09,1,0,null,8.49,null,0.20,2,2010-04-12),(166,00:00:00,8.30,1,4.77,4,10.99,5,9.11,null,0.36,2,2010-04-12)]

if i hard code the data as above mySQL accepts my request (except for some quibbles about formatting)

but if the variable clean_data is instead defined as the result of the parsing code, like this:

cleaner = [("""  $!!'""", ')]'),('  $!!', ') etc etc]
def processThis(str,lst):
    for find, replace in lst:
        str = str.replace(find, replace)
    return str
clean_data = processThis(data,cleaner)

then i get the dreaded “TypeError: not enough arguments for format string”

After playing with formatting options for a few hours (I am very new to this) I am confused… what is the difference between the hard coded data and the result of the processThis function as fas as mySQL is concerned?

Any idea greatly appreciated…

  • 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-14T06:45:04+00:00Added an answer on May 14, 2026 at 6:45 am

    Here is a stab at parsing your string into separate values:

    import datetime
    import time
    src = "161,00:00:00,8.19,1,4.46,4,7.87,4,6.54,null,4.45,6,2010-04-12"
    asFloat = lambda x : float(x)
    asInt = lambda x : int(x)
    asTime = lambda x : datetime.datetime(*time.strptime(x,'%H:%M:%S')[:7]).time()
    asDate = lambda x : datetime.datetime(*time.strptime(x,'%Y-%m-%d')[:3]).date()
    asNone = lambda x : None if x=='null' else int('ValueError')
    converters = (asDate,asTime,asInt,asFloat,asNone,)
    def convert(x):
      for cnv in converters:
        try:
          return cnv(x)
        except ValueError:
          pass
      return x
    
    clean_data = [convert(s) for s in src.split(',')]
    print clean_data
    

    Gives:

    [161, datetime.time(0, 0), 8.1899999999999995, 1, 4.46, 4, 
     7.8700000000000001, 4, 6.54, None, 4.4500000000000002, 6, 
     datetime.date(2010, 4, 12)]
    

    which should give a proper list for each row to pass to executemany.

    — Paul

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

Sidebar

Related Questions

Strange Question i guess but i have this bit of code in my page...
I would like to have some Javascript code running in a web browser write
I am trying to use this bit of code: [[myUIView layer] addSublayer: layer]; [myScrollView
I have this bit of code: ... ComplexNumber C1; ComplexNumber C2; cout << Enter
Hey all! This bit of code always returns 0, even though errcheck will have
I have a bit of code that I use to draw a border around
In a 32-bit .NET app, I can use this OLEDB connection string to connect
I tried to use this on my class library mylib.core.data.dll and got a successful
I am trying to use this in my page class. I only just started
I have this code: var params = Spry.Utils.getLocationParamsAsObject(); theLeague = params.league; switch (theLeague) {

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.