Update:
Here is the code that got me what I needed after using Achampion's resolution:
# make a list generated from a previous operation (dynamic list), eg. listA - listB = dynLst
dynLst
['R10YW', 'R13YW', 'R32YWBY','NOSVCYW']
# construct item request for a SQL statement using dynLst, this is Achampion's code
reqSQL = '(' + ', '.join([r"'{}'".format(x) for x in dynLst]) + ')'
# specify query field from table:
f1 = '\"Product_Code\"'
WC = f1 + ' IN ' + reqSQL
WC
'\"Product_Code\" IN (\'R10YW\', \'R13YW\', \'R32YWBY\',\'NOSVCYW\')'
I have a list composed of derived values from a prior python operation. The items in this list will change every time the previous python command runs. Therefor I need a dynamic way to format the list. I'm using it with the 'IN' operand as part of a SQL statement/where clause being used in a subsequent python function.
In order to build the where clause the right way I need it formatted like this:
field = '\"Product_Code\"'
qValues = '(\'R10YW\', \'R13YW\', \'R32YWBY\',\'NOSVCYW\')'
whereClause = field + ' IN ' + qValues
I've tried this:
qValues = '(\\'
for val in dynLst: # dynLst = a dynamic List
val = val + '\\'
qValues = qValues + val + "," + '\\'
qValues = qValues[:-1]
qValues = qValues + ')
But the format I get is this:
'(\\R10YW\\, \\R13YW\\, \\R32YWBY\\,\\NOSVCYW\\)'
I've also tried raw_string('(\') which I think is the python3 way of doing r"string\string", but no luck. I just get a syntax error.