Python,在双引号之间的字符串中检测带有引号的字符

Python, detect a character with on quote inside a string between double quotes

我有一个元组的例子:

('XXXX','XXXX',"XXXX's Something",'XXXX')

我想把它变成:

('XXXX','XXXX','XXXX''s Something','XXXX')

我尝试这样做的原因是,此输入将被吸收到 Azure SQL 数据库 中,该数据库使用另一个单引号跳过引号(如上图)

如何只检测双引号之间的字符内的单引号?

此致,

您可以使用 tuple() 和生成器表达式进行元组理解。

>>> t = ('XXXX','XXXX',"XXXX's Something",'XXXX')
>>> tuple(s.replace("'", "''") for s in t)
('XXXX', 'XXXX', "XXXX''s Something", 'XXXX')