[Tutor] String with literal %s
Alan Gauld
alan.gauld at btinternet.com
Thu Mar 20 17:18:35 CET 2014
On 20/03/14 14:46, Toni Fuente wrote:
> I am trying to create a string this way:
>
> insertion = "INSERT INTO mytable(week %s) VALUES (\%s, \%s)" % osStringI
>
> not enough arguments for format string
>
> Where the first %s is going to be substitute by the variable osStringI,
> but the other two VALUES (\%s, \%s), should be created as literals '%s'.
If you double the % sign it is treated as a percent character.
"INSERT INTO mytable(week %s) VALUES (%%s, %%s)"
But do you really want to do it this way?
Wouldn't it be better to use the SQLite parameter insertion syntax
and do it all at the execute stage?
cur.execute("INSERT INTO mytable(week ?) VALUES (?, ?)", val1,val2,val3)
just a thought,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list