a newbie question about gadfly
gbreed at cix.compulink.co.uk
gbreed at cix.compulink.co.uk
Wed Jun 13 10:30:51 EDT 2001
More information about the Python-list mailing list
Wed Jun 13 10:30:51 EDT 2001
- Previous message (by thread): a newbie question about gadfly
- Next message (by thread): a newbie question about gadfly
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
In article <vmoeit4n499fujuj5ine300ial3l94p81l at 4ax.com>, jm7potter at hotmail.com () wrote: > On 12 Jun 2001 15:34:16 GMT, gbreed at cix.compulink.co.uk wrote: > > >In article <hrbcit86g5gbmc63em9gc6tsji7nv78dqr at 4ax.com>, > >jm7potter at hotmail.com () wrote: > > > >> Why? is namex not a direct replacement for "donna" ???? > > > >Um, no, not the way you're doing it. Try replacing that magic > >line with > > > > > >Or even > > > >cursor.execute("insert into students (name, grade) values > >(%(namex)s, %(gradex)s)" % vars()) > > > >(that's sure to wordwrap!) > > > > > > Graham > > > Thanks for the help Graham, > > However, your code did not work either. The little program chokes every > time I try to > do anything that is not "hard-wired" into the script. Oops! There is an error: cursor.execute( "insert into students (name, grade) values ('%s', '%s')" % (namex, gradex)) might be better. I forgot to quote the arguments, and at least one of them is a string. > Oddly, the books that mention gadfly do not attempt anything but > hard-wired code. > Perhaps they know something? > > Hammond & Robinson cover gadfly in their "Python: programming on Win32" > (pp. 256 > -259) but never attempt to get data from a user and send it to the > database. Oh, you have that? I think the example right at the bottom of p.257 should do what you want. In your case insertstat = "insert into students (name, grade) values (?, ?)" cursor.execute(insertstat, (namex, gradex)) Just in case that doesn't work, I ran this code on the test database as set up in the middle of p.257 >>> bar = 'guiodos' >>> drinker = 'tim' >>> perweek = 35 >>> cursor.execute("insert into Frequents(perweek, bar, drinker) values (%s, '%s', '%s')"%(perweek, bar, drinker)) >>> cursor.execute('select * from frequents') >>> print cursor.pp() PERWEEK | BAR | DRINKER ============================ 1 | lolas | adam 3 | cheers | woody 5 | cheers | sam 3 | cheers | norm 2 | joes | wilt 1 | joes | norm 6 | lolas | lola 2 | lolas | norm 3 | lolas | woody 0 | frankies | pierre 1 | pans | peter 35 | guiodos | tim > For that matter, in "Learning Python" I see that Lutz & Ascher do not > even attempt > to get user input until page 200 when as an aside to exception handling > they tell us > about raw_input. Well, they do get user input via command line > arguments, but that > can take one only so far. And raw_input can only get you so far as well, so the emphasis is on GUIs for user input. Graham
- Previous message (by thread): a newbie question about gadfly
- Next message (by thread): a newbie question about gadfly
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list