a newbie question about gadfly
gbreed at cix.compulink.co.uk
gbreed at cix.compulink.co.uk
Thu Jun 14 09:33:35 EDT 2001
In article <pn7fitoa7n6u47atng7tv0n9aroc1716ic at 4ax.com>,
jm7potter at hotmail.com () wrote:
> Now, if you have the time and inclination --- could you
explain why
> your first code
> failed and the second worked? (I hate magic)
>
> And further, could you explain to a newbie why *my* code
failed?
It looks like this was answered to your satisfaction overnight.
> >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))
> >
>
> This does not work. I tried it before asking here on this ng.
>
> In fact, your suggestion is the very code I tried. I am at a
loss as to
> why it does
> not work in Python. It shows that I am missing some big deal
in my
> understanding of
> the language. Some major flaw in my understanding.
Are you sure you tried it exactly as written? It may be a
Gadfly bug, I doubt it's a language issue.
> Yes, I see how this would work --- I did not even need to try
it.
>
> But, this is not what was used on page 257.
This is how you'd do it that way, exactly as it worked for me
except I used a multiline string to correct for wordwrap:
>>> from gadfly import gadfly
>>> connection = gadfly('test','dbtest')
>>> cursor = connection.cursor()
>>> insertstat = "insert into Frequents" \
"(perweek, bar, drinker) values(?,?,?)"
>>> perweek=35
>>> bar='guidos'
>>> drinker='tim'
>>> cursor.execute(insertstat, (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 | guidos | tim
> I learned C about 15 years ago. I learned to use the language
with very
> simple i/o
> --- and later explained to more sophisticated GUI interfaces.
>
> Some of us old guys may need to do the same with Python.
Hmm, it must be over 15 years ago I learned Basic. Funnily
enough, I've never used raw_input that I can remember, over the
year or so I've been playing with Python. I use the interpreter
interactively for that very simple I/O. It's one of the things
I really like about Python.
Graham
More information about the Python-list
mailing list