I want to replace a string (‘None’) with NULL without quote.
For example:
data = ('a','None','1','None')
And desired result:
result = "'a', NULL, '1', NULL"
Is there a way to get the expected result? Thanks in advance!!
>Solution :
You can use join to build the resulting string:
data = ('a','None','1','None')
t = ', '.join('NULL' if t == 'None' else repr(t) for t in data)
t is then the string "'a', NULL, '1', NULL".
But I really cannot imagine a real world use case for that…