Στις 6/8/2010 2:46 πμ, ο/η Tim Chase έγραψε:
# variant B
for row in dataset:
host, hits, dt = row
# rest of your code here
So, row is a tuple comprising of 3 fields,
and host, hist, dt are variables assigned each one of row's tuple values
by breaking it to it's elements.
But what kind of objects is host, hits, dt that containes the row's
tuple data themselves? tuples or lists and why?
# variant C
for host, hits, dt in row:
# rest of your code here
host, hits, data each and every one of them hold a piece of the row's
tuple values.
But what happens in here?
'for host, hits, dt in dataset:'
Here we don't have the row tuple. So what tthose variabels store, and in
what datatype they strore info in and what is the difference between this
and
'for host, hits, dt in row:'
What datatypes are these vars here and what data each one hold?
The data-type of the individual values would be whatever comes back
from the database as translated into Python (string, float/Decimal,
boolean, datetime, etc). In your example, it's likely a
string+integer+datetime as the 3 values. You can see why I prefer the
elegance of just performing the assignment in the for-loop (variant C).
If the fieds datatypes returned form the database are for exmaple page
varchar(50) , hits inteeger[11], date datetime then
the when python grabs those results fields it would translate them to
'page as string' , (hits as int) , 'date as string' respectively?
Whcih emans it translated those fileds returned to the most
appropriate-most close to prototype stored in database' datatypes
automatically?
[*] "about" the same because in #1 and #2, you also have access to the
whole row; whereas in #3, you don't have something called "row", but
you could reassemble it if you needed:
row = (host, hits, dt
Would that be a row or a tuple when joined?
Again, thanks for ALL your preciosu help you provide me!
--
http://mail.python.org/mailman/listinfo/python-list