On 19/05/16 10:03, Crusier wrote: > c.execute('''CREATE TABLE stocks > (code text)''') > > # Insert a row of data > List = ['00001', '00002', '00003', '00004', '00005', '00006', '00007', > '00008', '00009', '00010', '00011', '00012'] > > c.executemany('INSERT INTO stocks VALUES (?)', List)
Peter has already given you one answer, I'll repeat it in a slightly different form. Between the two of us you will hopefully understand... :-) the SQL statement INSERT INTO stocks VALUES (?) Has a placemarker (?) that execute() or executemany()expect a sequence to fill. This is more obvious if you had more than one variable: INSERT INTO stocks VALUES (?, ?) Here it would expect a sequence of two values. But although you only have one value, execute() still expects a sequence, but one that contains a single value. You are providing strings which are sequences of 5 characters, so exec tries to process the 5 characters but has only 1 placemarker so it fails. So you need to pass a sequence (usually a tuple) of one value like: ('12345',) # note the comma at the end. execmany() is exactly the same but expects a sequence of sequences. So you need your list to contain tuples as above stock_codes = [('12345',), ('23456',), ...] HTH -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor