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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -