Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 格式字符串中遇到单个“}”_Python_Mysql - Fatal编程技术网

Python 格式字符串中遇到单个“}”

Python 格式字符串中遇到单个“}”,python,mysql,Python,Mysql,我有一个usertable,它有一列“routes”,它的值类似于“[{407:410},{410:408}]”。我需要选择所有具有值408}的行,所以我在中使用like关键字 MySQL来实现这一点。查询如下所示 从usertable中选择路由,其中的路由类似于“%408}%” 这个查询在MySQL Workbench中工作,但当我将其转换为Python时,它不工作,我的查询在Python中如下所示 从usertable中选择路由,其中包含类似“{1}}%”的路由。formatroutes`

我有一个usertable,它有一列“routes”,它的值类似于“[{407:410},{410:408}]”。我需要选择所有具有值408}的行,所以我在中使用like关键字 MySQL来实现这一点。查询如下所示 从usertable中选择路由,其中的路由类似于“%408}%”

这个查询在MySQL Workbench中工作,但当我将其转换为Python时,它不工作,我的查询在Python中如下所示 从usertable中选择路由,其中包含类似“{1}}%”的路由。formatroutes`

我看到的错误如下:

    "Single '}' encountered in format string"
我确实尝试过使用转义字符,即.}和}},但仍然得到相同的错误

请建议如何修复此问题

谢谢, Seema

'{1}}%'.formatroutes'应该是'{1}}}%'。formatroutes'注意双精度}}}

这就是如何使格式不尝试填充值,而只返回一个}。如合同所述:

花括号外的绳子部分按字面意思处理, 除了任何双大括号“{{”或“}}”替换为 对应的单花括号

如果要使用格式,则应复制}和{

在您的情况下,请编辑字符串,使其看起来像“{1}}%”。formatroutes。这将给出您期望的结果

至于

我试过使用转义字符


似乎您试图转义用于格式化的字符,而不是您不想触摸的字符。

尝试使用以下查询

select routes from usertable where routes like '%%{{\"{1}\"%%'".format(routes))
您正在使用的%是转义字符,您可以使用%%代替%同样地代替{use{{和add\之前

这对你有帮助