Re: [Tutor] genfromtxt and dtype to convert data to correct format
Thanks Alan! Taking the strtime off did not work either and printed dattime.dattime(very long date format). I was able to get the integer and string parts fixed via dtype, but could not do the same for date and time. I have a feeling that structured arrays might do the trick but don't know yet how. Thanks again--EK ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] genfromtxt and dtype to convert data to correct format
On 19/05/16 01:31, Ek Esawi wrote: > Thanks Alan! > > Taking the strtime off did not work either and printed dattime.dattime(very > long date format). But isn't that just the representation of a datetime object (which is what strptime produces)? In other words it's an object not a string. Can you show us what you get back? Or try printing the type() of the object: eg. print (type( row[1]) print (type( row[3]) You may be getting confused between the representation of the object and the actual data. But until we see some actual code and the actual output it produces it is hard to be sure. Can you send us a cut 'n paste of an actual python session so that we can see the parameters to genfromtxt and how you are producing the output? For example I'd expect something like: >>> import datetime as dt >>> d = dt.datetime.strptime("07/05/2015","%m/%d/%Y") >>> t = (1,d,'foo') >>> print(t) (1, datetime.datetime(2015, 7, 5, 0, 0), 'foo') >>> Notice the middle entry is a datetime object, which is, I think, what you want? You can get just the date (or time) portion if you want by calling the appropriate method. You could do that in your lambdas: >>> CF = lambda datestr: dt.datetime.strptime(datestr, '%m/%d/%Y').date() >>> d2 = CF('11/08/2012') >>> data = (1,d2,'My string') >>> print(data) (1, datetime.date(2012, 11, 8), 'My string') >>> 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
[Tutor] SQLite
Dear Alan, I have read your web page and try to test thing out on SQLite. Attached is my code: import sqlite3 conn = sqlite3.connect('example1.db') c = conn.cursor() c.execute('drop table if exists stocks') c.execute('''CREATE TABLE stocks (code text)''') # Insert a row of data List = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '00010', '00011', '00012'] c.executemany('INSERT INTO stocks VALUES (?)', List) # Save (commit) the changes conn.commit() # We can also close the connection if we are done with it. # Just be sure any changes have been committed or they will be lost. conn.close() The following error has came out sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 5 supplied. Please advise. Thank you very much. Regards, Crusier ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SQLite
Crusier wrote: > Dear Alan, > > I have read your web page and try to test thing out on SQLite. > > Attached is my code: > > import sqlite3 > conn = sqlite3.connect('example1.db') > c = conn.cursor() > c.execute('drop table if exists stocks') > c.execute('''CREATE TABLE stocks > (code text)''') > > # Insert a row of data > List = ['1', '2', '3', '4', '5', '6', '7', > '8', '9', '00010', '00011', '00012'] List is a bad name; use something related to the problem domain, e. g stocks. > > c.executemany('INSERT INTO stocks VALUES (?)', List) > > # Save (commit) the changes > conn.commit() > > # We can also close the connection if we are done with it. > # Just be sure any changes have been committed or they will be lost. > conn.close() > > The following error has came out > sqlite3.ProgrammingError: Incorrect number of bindings supplied. The > current statement uses 1, and there are 5 supplied. > > Please advise. The List argument is interpreted as a sequence of records and thus what you meant as a single value, e. g. "1" as a sequence of fields, i. e. every character counts as a separate value. To fix the problem you can either change the list to a list of tuples or lists List = [['1'], ['2'], ['3'], ...] or add a zip() call in the line c.executemany('INSERT INTO stocks VALUES (?)', zip(List)) which has the same effect: >>> list(zip(["foo", "bar", "baz"])) [('foo',), ('bar',), ('baz',)] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] genfromtxt and dtype to convert data to correct format
Thanks again! I tried a combination of the suggestions and still not getting what i want. Here are the original code, file, and output. CODE mport csv; import numpy as np; from datetime import datetime, date, time CF = lambda date: datetime.strptime(bytes.decode(date), '%m/%d/%Y').strftime('%Y-%m-%d') CF1 = lambda time: datetime.strptime(bytes.decode(time), '%H:%M').strftime('%H:%M:%S') MyFile='c:/Users/EK Esawi/My Documents/Temp/GOSA-3.csv' CRNs={'Date': CF,'Time':CF1,'Interval':CF1,'Duration':CF1,'Preplay':CF1,'Prediction':CF1} data = np.genfromtxt(MyFile, names=True,delimiter=',',converters=CRNs,dtype=None) print(data) INPUT O Date Geyser Time Interval Duration Preplay Heght Prediction 312171 7/1/1995 Position 13:37 1:43 4:42 13:16 162 13:19 358237 5/25/1993 Position 12:22 1:31 4:16 12:03 160 12:13 339971 7/17/1994 Position 15:54 1:23 4:36 15:43 160 15:51 OUTPUT [ (312171, '1995-07-01', b'Old Faithful', '13:37:00', '01:43:00', '04:42:00', '13:16:00', 162, '13:19:00') (358237, '1993-05-25', b'Old Faithful', '12:22:00', '01:31:00', '04:16:00', '12:03:00', 160, '12:13:00') (339971, '1994-07-17', b'Old Faithful', '15:54:00', '01:23:00', '04:36:00', '15:43:00', 160, '15:51:00') ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] FTP file transfer stops, no error given
The Python script has two objectives: a) create a web page from data in an Excel spreadsheet, b) upload that web page to a web server using ftp. In a nutshell the problem is that if the two objectives are combined into one Python script, ftp stops uploading in the middle of the file, but if the same code is split into two files, web page creation in one script and ftp in another, and they are run separately, ftp uploads the entire file and it all works. Below are the details. Script #1: Create web page import glob, os, sys, unicodedata imagesdirectory = 'C:\\Users\\craig\\Desktop\\Network Drives\\Documents\\Volunteer and Nonprofit\\Peckerwood Garden\\tour guide information\\images\\' spreadsheet='C:\\Users\\craig\\Desktop\\Network Drives\\Documents\\Volunteer and Nonprofit\\Peckerwood Garden\\tour guide information\\index2.xlsx' # load excel file and set directory variables from openpyxl import load_workbook wb = load_workbook(filename = spreadsheet, data_only = True) ws = wb.get_sheet_by_name('Garden') numberofrecords = ws.cell(row = 1, column = 1).value htmlpage = open('C:\\Users\\craig\\Desktop\\Network Drives\\Documents\\Volunteer and Nonprofit\\Peckerwood Garden\\tour guide information\\index2.html', 'w') htmlpage.write('Peckerwood Garden Docent Notes\n') htmlpage.write('') htmlpage.write('') htmlpage.write('\n') htmlpage.write('\n') htmlpage.write('\n') htmlpage.write('\n') htmlpage.write('Unique ID\n') htmlpage.write('Location\n') htmlpage.write('Name\n') htmlpage.write('Family\n') htmlpage.write('Common Name\n') htmlpage.write('Nativity\n') htmlpage.write('Photographs\n') htmlpage.write('Description\n') htmlpage.write('\n') # loop through excel spreadsheet, search images directory, create html file for i in range(2,numberofrecords + 2): uniqueid = str(ws.cell(row = i, column = 2).value) location = unicodedata.normalize('NFKD', ws.cell(row = i, column = 3).value).encode('ascii','ignore') name = unicodedata.normalize('NFKD', ws.cell(row = i, column = 4).value).encode('ascii','ignore') if ws.cell(row = i, column = 5).value: family = unicodedata.normalize('NFKD', ws.cell(row = i, column = 5).value).encode('ascii','ignore') else: family = "" if ws.cell(row = i, column = 6).value: commonname = unicodedata.normalize('NFKD', ws.cell(row = i, column = 6).value).encode('ascii','ignore') else: commonname = "" if ws.cell(row = i, column = 7).value: nativity = unicodedata.normalize('NFKD', ws.cell(row = i, column = 7).value).encode('ascii','ignore') else: nativity = "" if ws.cell(row = i, column = 8).value: description = unicodedata.normalize('NFKD', ws.cell(row = i, column = 8).value).encode('ascii','ignore') else: description = "" htmlpage.write('\n') htmlpage.write('' + uniqueid + '\n') htmlpage.write('' + location + '\n') htmlpage.write('' + name + '\n') htmlpage.write('' + family + '\n') htmlpage.write('' + commonname + '\n') htmlpage.write('' + nativity + '\n') htmlpage.write('') for x in glob.glob(imagesdirectory + uniqueid + '*'): htmlpage.write ('Photo\n') htmlpage.write('') htmlpage.write('' + description +'\n') htmlpage.write('') htmlpage.close Script #2: Use FTP to upload files # open ftp and copy up web files from ftplib import FTP ftp = FTP('wildtrip.com','user','pass') ftp.set_debuglevel(2) ftp.cwd('/wildtrip.com/tour/css/') filename = 'C:\\Users\\craig\\Desktop\\Network Drives\\Documents\\Volunteer and Nonprofit\\Peckerwood Garden\\tour guide information\\css\\stylesheet.css' ftp.storlines("STOR stylesheet.css", open(filename, 'r')) ftp.cwd('/wildtrip.com/tour/') filename = 'C:\\Users\\craig\\Desktop\\Network Drives\\Documents\\Volunteer and Nonprofit\\Peckerwood Garden\\tour guide information\\index2.html' ftp.storlines("STOR index.html", open(filename, 'r')) ftp.quit() Combined scripts have output as follows: the last lines of the html file on the local disk: Photo Photo As you can see the script correctly wrote the html code to the local file. However, ftp upload of this very same local file terminates. The last lines of the uploaded file: Photo Photo https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] genfromtxt and dtype to convert data to correct format
On 19/05/16 12:51, Ek Esawi wrote: > Thanks again! > > I tried a combination of the suggestions and still not getting what i want. > > Here are the original code, file, and output. > > CODE > > mport csv; import numpy as np; from datetime import datetime, date, time > > CF = lambda date: datetime.strptime(bytes.decode(date), > '%m/%d/%Y').strftime('%Y-%m-%d') Again you have strftime at the end so it will result in a string output. You need to remove that if you want a date/time/datetime object as a result. That's assuming that it is a datetime style object that you want. -- 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
Re: [Tutor] SQLite
On 19/05/16 10:03, Crusier wrote: > c.execute('''CREATE TABLE stocks > (code text)''') > > # Insert a row of data > List = ['1', '2', '3', '4', '5', '6', '7', > '8', '9', '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
Re: [Tutor] FTP file transfer stops, no error given
On 19/05/16 15:11, Craig Jackson wrote: > ftp. In a nutshell the problem is that if the two objectives are > combined into one Python script, ftp stops uploading in the middle of > the file, but if the same code is split into two files, web page > creation in one script and ftp in another, and they are run > separately, ftp uploads the entire file and it all works. Below are > the details. Unfortunately you seem to have sent the variation that works. We cannot really tell what is going on unless we can see the code that fails. There is one possibility based on the code below... > htmlpage.write(' charset="UTF-8">Peckerwood Garden Docent Notes\n') > htmlpage.write('') > htmlpage.write('') > htmlpage.write('\n') > htmlpage.write('\n') > htmlpage.write('\n') > htmlpage.write('\n') > htmlpage.write('Unique ID\n') > htmlpage.write('Location\n') > htmlpage.write('Name\n') > htmlpage.write('Family\n') > htmlpage.write('Common Name\n') > htmlpage.write('Nativity\n') > htmlpage.write('Photographs\n') > htmlpage.write('Description\n') > htmlpage.write('\n') Consider using triple quoted strings to save yourself a lot of typing and to make the html easier to read. > ... > htmlpage.write('') > htmlpage.write('' + description +'\n') > htmlpage.write('') > htmlpage.close Note that there are no parens after close. So you do not execute the function and the file is not closed. If you then try to ftp the still open file that could explain the problems you are having. Whereas if you run this as a separate script the file will be auto-closed at the end of the script so running the ftp separately will work.. -- 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
[Tutor] Create a pivot table
Dear All! This is my data from a file. I want to obtain a count table how many times c11 are present for each project and Samples and Program. ['Program', 'Sample', 'Featurename', 'Project'], ['A', 'A100', 'c11', 'post50'], ['A', 'A100', 'c12', 'post50'], ['A', 'A100', 'c14', 'post50'], ['A', 'A100', 'c67', 'post50'], ['A', 'A100', 'c76', 'post50'], ['B', 'A100', 'c11', 'post50'], ['B', 'A100', 'c99', 'post50'], ['B', 'D33', 'c33', 'post50'], ['B', 'D33', 'c31', 'post50'], ['C', 'D34', 'c32', 'post60'], ['C', 'D35', 'c33', 'post60'], ['C', 'D36', 'c11', 'post60'], ['C', 'D37', 'c45', 'post60'], ['C', 'D38', 'c36', 'post60'], ['C', 'D39', 'c37', 'post60'] I want to obtain pivot table with samples on columns and program as rown and the values I want fusionwhat it is the best way to do this?thanks in advance! ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Create a pivot table
jarod_v6--- via Tutor wrote: > Dear All! > This is my data from a file. I want to obtain a count table how many > times c11 are present for each project and Samples and Program. > > ['Program', 'Sample', 'Featurename', 'Project'], > ['A', 'A100', 'c11', 'post50'], > ['A', 'A100', 'c12', 'post50'], > ['A', 'A100', 'c14', 'post50'], > ['A', 'A100', 'c67', 'post50'], > ['A', 'A100', 'c76', 'post50'], > ['B', 'A100', 'c11', 'post50'], > ['B', 'A100', 'c99', 'post50'], > ['B', 'D33', 'c33', 'post50'], > ['B', 'D33', 'c31', 'post50'], > ['C', 'D34', 'c32', 'post60'], > ['C', 'D35', 'c33', 'post60'], > ['C', 'D36', 'c11', 'post60'], > ['C', 'D37', 'c45', 'post60'], > ['C', 'D38', 'c36', 'post60'], > ['C', 'D39', 'c37', 'post60'] > I want to obtain pivot table with samples on columns and program as rown > and the values I want fusionwhat it is the best way to do this?thanks in > advance! With the pivot() function from https://mail.python.org/pipermail/tutor/2016-April/108671.html >>> rows = [ ... ['A', 'A100', 'c11', 'post50'], ... ['A', 'A100', 'c12', 'post50'], ... ['A', 'A100', 'c14', 'post50'], ... ['A', 'A100', 'c67', 'post50'], ... ['A', 'A100', 'c76', 'post50'], ... ['B', 'A100', 'c11', 'post50'], ... ['B', 'A100', 'c99', 'post50'], ... ['B', 'D33', 'c33', 'post50'], ... ['B', 'D33', 'c31', 'post50'], ... ['C', 'D34', 'c32', 'post60'], ... ['C', 'D35', 'c33', 'post60'], ... ['C', 'D36', 'c11', 'post60'], ... ['C', 'D37', 'c45', 'post60'], ... ['C', 'D38', 'c36', 'post60'], ... ['C', 'D39', 'c37', 'post60'] ... ] >>> table = pivot(rows, operator.itemgetter(1), operator.itemgetter(0), lambda r: r[2] == "c11") >>> csv.writer(sys.stdout, delimiter="\t").writerows(table) A100D33 D34 D35 D36 D37 D38 D39 A 1 -/- -/- -/- -/- -/- -/- -/- B 1 0 -/- -/- -/- -/- -/- -/- C -/- -/- 0 0 1 0 0 0 There are probably many other options, but you should seriously consider using a spreadsheet application. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] FTP file transfer stops, no error given
Adding the parentheses worked. So sorry for taking your time. I'm new to Python and not at all a programmer. Thanks for your help. On Thu, May 19, 2016 at 11:37 AM, Alan Gauld via Tutor wrote: > On 19/05/16 15:11, Craig Jackson wrote: > >> ftp. In a nutshell the problem is that if the two objectives are >> combined into one Python script, ftp stops uploading in the middle of >> the file, but if the same code is split into two files, web page >> creation in one script and ftp in another, and they are run >> separately, ftp uploads the entire file and it all works. Below are >> the details. > > Unfortunately you seem to have sent the variation that works. > We cannot really tell what is going on unless we can see the > code that fails. > > There is one possibility based on the code below... > >> htmlpage.write('> charset="UTF-8">Peckerwood Garden Docent Notes\n') >> htmlpage.write('') >> htmlpage.write('') >> htmlpage.write('\n') >> htmlpage.write('\n') >> htmlpage.write('\n') >> htmlpage.write('\n') >> htmlpage.write('Unique ID\n') >> htmlpage.write('Location\n') >> htmlpage.write('Name\n') >> htmlpage.write('Family\n') >> htmlpage.write('Common Name\n') >> htmlpage.write('Nativity\n') >> htmlpage.write('Photographs\n') >> htmlpage.write('Description\n') >> htmlpage.write('\n') > > Consider using triple quoted strings to save yourself a lot of typing > and to make the html easier to read. > >> ... >> htmlpage.write('') >> htmlpage.write('' + description +'\n') >> htmlpage.write('') >> htmlpage.close > > Note that there are no parens after close. So you do not execute the > function and the file is not closed. > > If you then try to ftp the still open file that could explain the > problems you are having. Whereas if you run this as a separate script > the file will be auto-closed at the end of the script so running the > ftp separately will work.. > > > -- > 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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Getting started in testing
Is anyone aware of any good tutorials on testing one's Python code? These days, I'm a hobby programmer, writing little things just for my own use, and don't really sweat testing much. But I do have one niche open-source project where I need to be a bit more regimented, and specifically need to develop a set of tests to be passed before releasing. Any resources would be helpful. I am aware of the docs on unittest, but I'm looking for a more tutorial approach. I use Python 2.7, and my project is a module with no GUI, if that matters. Thanks. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] FTP file transfer stops, no error given
On 19/05/16 19:01, Craig Jackson wrote: > Adding the parentheses worked. So sorry for taking your time. I'm new > to Python and not at all a programmer. Thanks for your help. No trouble, that's what the list is here for. Just remember next time to post the code that fails rather than the code that works, it saves us guessing :-) And if you do get error messages always post the entire message, don't summarize it. -- 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
Re: [Tutor] Getting started in testing
On 19/05/16 20:34, Terry Carroll wrote: > Is anyone aware of any good tutorials on testing one's Python code? I'm not a big fan of video tutorials but I recently had to teach myself Junit testing (and mockito) in Java and I found that Youtube videos really helped. I know there are similar videos on Python's unittest (as well as alternatives such as nose). So a Youtube search might be a good start. And since most are only 10 minutes or so long you won't waste much time if you decide they aren't working for you. -- 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
Re: [Tutor] Tutor Digest, Vol 147, Issue 30
Dear Peter & Alan, Thanks alot. Have a great day Cheers, Hank On Fri, May 20, 2016 at 12:00 AM, wrote: > Send Tutor mailing list submissions to > tutor@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > https://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > >1. Re: SQLite (Peter Otten) > > > -- > > Message: 1 > Date: Thu, 19 May 2016 11:20:32 +0200 > From: Peter Otten <__pete...@web.de> > To: tutor@python.org > Subject: Re: [Tutor] SQLite > Message-ID: > Content-Type: text/plain; charset="ISO-8859-1" > > Crusier wrote: > >> Dear Alan, >> >> I have read your web page and try to test thing out on SQLite. >> >> Attached is my code: >> >> import sqlite3 >> conn = sqlite3.connect('example1.db') >> c = conn.cursor() >> c.execute('drop table if exists stocks') >> c.execute('''CREATE TABLE stocks >> (code text)''') >> >> # Insert a row of data >> List = ['1', '2', '3', '4', '5', '6', '7', >> '8', '9', '00010', '00011', '00012'] > > List is a bad name; use something related to the problem domain, e. g > stocks. > >> >> c.executemany('INSERT INTO stocks VALUES (?)', List) >> >> # Save (commit) the changes >> conn.commit() >> >> # We can also close the connection if we are done with it. >> # Just be sure any changes have been committed or they will be lost. >> conn.close() >> >> The following error has came out >> sqlite3.ProgrammingError: Incorrect number of bindings supplied. The >> current statement uses 1, and there are 5 supplied. >> >> Please advise. > > The List argument is interpreted as a sequence of records and thus what you > meant as a single value, e. g. "1" as a sequence of fields, i. e. every > character counts as a separate value. > > To fix the problem you can either change the list to a list of tuples or > lists > > List = [['1'], ['2'], ['3'], ...] > > or add a zip() call in the line > > c.executemany('INSERT INTO stocks VALUES (?)', zip(List)) > > which has the same effect: > list(zip(["foo", "bar", "baz"])) > [('foo',), ('bar',), ('baz',)] > > > > > > -- > > Subject: Digest Footer > > ___ > Tutor maillist - Tutor@python.org > https://mail.python.org/mailman/listinfo/tutor > > > -- > > End of Tutor Digest, Vol 147, Issue 30 > ** ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Getting started in testing
On Thu, May 19, 2016 at 12:34 PM, Terry Carroll wrote: > Is anyone aware of any good tutorials on testing one's Python code? > > These days, I'm a hobby programmer, writing little things just for my own > use, and don't really sweat testing much. But I do have one niche > open-source project where I need to be a bit more regimented, and > specifically need to develop a set of tests to be passed before releasing. > > Any resources would be helpful. I am aware of the docs on unittest, but I'm > looking for a more tutorial approach. Hi Terry, The section on Unit Testing in Dive Into Python: http://www.diveintopython.net/unit_testing/ I have fond memories of "Test Driven Development: By Example" by Kent Beck, so that might be worth looking into. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor