pylint woes

Jussi Piitulainen jussi.piitulainen at helsinki.fi
Sun May 8 01:50:12 EDT 2016


DFS writes:

> The lists I actually use are:
>
> for j in range(len(nms)):
>      cSQL = "INSERT INTO ADDRESSES VALUES (?,?,?,?,?)"
>      vals = nms[j],street[j],city[j],state[j],zipcd[j]
>
>
> The enumerated version would be:
>
> ziplists = zip(nms,street,city,state,zipcd)
> for nm,street,city,state,zipcd in ziplists:
>      cSQL = "INSERT INTO ADDRESSES VALUES (?,?,?,?,?)"
>      vals = nm,street,city,state,zipcd
>
>
> I guess the enumeration() is a little nicer to look at.  Why do you
> think it's more maintainable?

The following variations avoid the naming of the result of zip at all,
and also save a line or two, depending on what you actually do in the
loop, without introducing overly long lines. Judge for yourself.

You don't need to name the individual components, if you only actually
use vals:

for vals in zip(nms,street,city,state,zipcd):
    cSQL = "INSERT INTO ADDRESSES VALUES (?,?,?,?,?)"


Or you can opt to name the tuple and its components the other way
around:

for vals in zip(nms,street,city,state,zipcd):
    nm,street,city,state,zipcd = vals
    cSQL = "INSERT INTO ADDRESSES VALUES (?,?,?,?,?)"



More information about the Python-list mailing list