python - Using list of rows whether I have 1 row or N many -


i have

foo=("bob","smith","123") 

and sometimes

foo=(("bob","smith","123"),("sam","smith","124")) 

and loop:

for rows in foo: 

but want loop treat foo list of rows if 1 row inside instead of n many. right if passed in 1st foo, iterate bob, smith, 123 if pass 2nd foo iterate rows (which want). objects pyodbc.row.

another way of saying want able use:

foo[0][1]=stuff 

if passed many rows, or one.

how can this?

a trick use inside function accepts different types of inputs first normalize uncommon input common type, , handle common type. similarly, in case (untested):

if not isinstance(foo[0], tuple):  # single row     foo = (foo,)  # add row tuple of lenght 1  row in foo:  # sure foo tuple of rows     # row 

Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -