On 5/8/2016 11:51 AM, Steven D'Aprano wrote:
On Mon, 9 May 2016 12:25 am, DFS wrote:
for j in range(len(nms)):
cSQL = "INSERT INTO ADDRESSES VALUES (?,?,?,?,?)"
vals = nms[j],street[j],city[j],state[j],zipcd[j]
Why are you assigning cSQL to the same string over and over again?
I like it in cloxe proximity to the vals statement.
Sure, assignments are cheap, but they're not infinitely cheap. They still
have a cost. Instead of paying that cost once, you pay it over and over
again, which adds up.
Adds up to what?
Worse, it is misleading. I had to read that code snippet three or four times
before I realised that cSQL was exactly the same each time.
You had to read 5 words three or four times? Seriously?
I tried:
for nm,street,city,state,zipcd in zip(nms,street,city,state,zipcd):
but felt it was too long and wordy.
It's long and wordy because you're doing something long and wordy. It is
*inherently* long and wordy to process five things, whether you write it
as:
for i in range(len(names)):
name = names[i]
street = streets[i]
city = cities[i]
state = states[i]
zipcode = zipcodes[i]
process(...)
or as:
for name, street, city, state, zipcode in zip(
names, streets, cities, states, zipcodes
):
process(...)
I like mine best of all:
ziplists = zip(names,streets,cities,states,zipcodes)
for name,street,city,state,zipcode in ziplists:
I like the first one better. python is awesome, but too many options
for doing the same thing also makes it difficult. For me, anyway.
That's the difference between a master and an apprentice. The apprentice
likes to follow fixed steps the same way each time. The master craftsman
knows her tools backwards, and can choose the right tool for the job, and
when the choice of tool really doesn't matter and you can use whatever
happens to be the closest to hand.
"her tools"... you're a woman?
--
https://mail.python.org/mailman/listinfo/python-list