python - How to convert a tuple (in place) to first item in list? -


i have boiler plate code performs sql queries , returns results (this based off of working code written years ago else). generally, code return list of tuples, totally fine need.

however, if there's 1 result, code returns single tuple instead, , breaks code expects loop through list of tuples.

i need easy way convert tuple first item of list, can use in code expecting loop through lists.

what's straightforward way in single line of code?

i figured there must straightforward way this, , there is. if result set called rows:

if not isinstance(rows,list):     rows = [rows] 

i don't know if pythonic construction, or if there's way of combining isintance , rows = [rows] lines single statement.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -