简体   繁体   English

原始 f 字符串中不支持的格式字符

[英]Unsupported format character in raw f-string

I'm trying to execute the following query using sqlalchemy.我正在尝试使用 sqlalchemy 执行以下查询。

engine=sqlalchemy.create_engine('mysql+pymysql://root:root@localhost:3306/cst')

cst_delete_query = rf"""delete from customer where STATUS like '%CT%'"""

with engine.connect().execution_options(autocommit=True) as conn:
     conn.execute(cst_delete_query)

This results in the following error:这会导致以下错误:

ValueError: unsupported format character 'C' (0x43) at index 41

The percent character is a string operator and should be escaped to be used in a string.百分比字符是一个字符串运算符,应该转义以在字符串中使用。 You can escape it with a second % .你可以用第二个%来逃避它。

cst_delete_query = rf"DELETE FROM customer WHERE status LIKE '%%CT%%'"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM