Python When To Use Nested Functions Mysql Commands