【错误】python百分号冲突not enough arguments for format string
query = "SELECT * FROM devices WHERE devices.`id` LIKE '%{}%'".format("f2333")
datas = cur.query(query)
报错:
query = query % tuple([db.literal(item) for item in args])
TypeError: not enough arguments for format string
传入query语句拼接出来为
SELECT * FROM devices WHERE devices.`mac` LIKE '%f8272e010882%'
此时还在python解释器中运行,这里的%加后面的字符会被python解析为占位符,如%f为float,所以报错缺少参数。
解决
使用转义,转义%要使用%转义。
query = "SELECT * FROM devices WHERE devices.`id` LIKE '%%{}%%'".format("f2333")
datas = cur.query(query)
【错误】python百分号冲突not enough arguments for format string的更多相关文章
- Python TypeError: not enough arguments for format string
今天使用mysqldb执行query语句的时候,在执行这条语句的时候: select PROJ, DATE_FORMAT(MAX(DATE),'%Y-%m-%') AS MAXDATE, DATE_F ...
- 使用Python过程出现的细节问题:TypeError: not enough arguments for format string
今天使用字符串格式化时,遇到的一点小问题:调用这个方法解释器出错了:TypeError: not enough arguments for format string def ll(name,age) ...
- TypeError: not enough arguments for format string
到一个问题,表示100% 的时候,出现这个问题. 因为python语法会认为是你需要转移符,这个时候你可以选择100%% 来表示
- Python TypeError: not all arguments converted during string formatting ——元组tuple(a)和(a,)的区别
今天写程序,想输出一个array的shape,原程序为: print('shape of testUImatrix:%s\nStart to make testUImatrix...'%(testui ...
- The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the arguments (int, SettingFragment, String)
The method replace(int, Fragment, String) in the type FragmentTransaction is not applicable for the ...
- The method format(String, Object[]) in the type String is not applicable for the arguments
今天,我弟遇到一个有意思的错误~ 程序: package com.mq.ceshi1; public class StringFormat { public static void main(Stri ...
- [BTS] Error biztalk arguments null exception string reference not set to an instance of a string. parameter name
biztalk arguments null exception string reference not set to an instance of a string. parameter name ...
- python安装pbkdf2 遇到错误TypeError: __call__() takes exactly 2 arguments (1 given)
python安装模块时遇到如下错误, import packaging.requirements File "/usr/lib/python2.7/site-packages/packagi ...
- SVN常见错误和版本冲突解决
之前在Eclipse下面误删除了svn的一些插件包,后来重装了就问题重重,在这里还是建议, Windows下SVN最好使用桌面版,在文件管理器下面更新和提交. 1.常见错误整理 #, c-format ...
随机推荐
- Building Applications with Force.com and VisualForce (DEV401) (二三):Visualforce Componets (Tags) Library Part III
Dev401-024:Visualforce Pages: Visualforce Componets (Tags) Library Part IIIStatic Resources1.Static ...
- python之目录
一.python基础 python之字符串str操作方法 python之int (整型) python之bool (布尔值) python之str (字符型) python之ran ...
- python之面向对象性封装,多态,以及鸭子类型
默认类型 class A: class_name = 'python23期' def __init__(self, name, age): self.name = name self.age =age ...
- 一、【Docker笔记】进入Docker世界
我们平时判断一个电脑的性能主要看什么?磁盘读写?CPU的主频高低?还是内存的大小?可是作为个人使用者来说,这些参数高一些足够我们去使用了,可是对于一个大型系统甚至是超大型系统,当前的硬件是远远达不 ...
- EntityFramework Core 3.x添加查询提示(NOLOCK)
前言 前几天看到有园友写了一篇关于添加NOLOCK查询提示的博文<https://www.cnblogs.com/weihanli/p/12623934.html>,这里呢,我将介绍另外一 ...
- nginx负载均衡例子
upstream demo { ip_hash;//客户连接后, 一直用这个IP,直到会话结束,否则,动态程序可能会在换IP后出错 server 192.168.1.1:80 weight=5 | d ...
- iOS 继承
是否使用继承需要考虑三个点: 父类只是给子类提供服务,并不涉及子类的业务逻辑 层级关系明显,功能划分清晰,父类和子类各做各的. 父类的所有变化,都需要在子类中体现,也就是说此时耦合已经成为需求 万不得 ...
- 7.Maven命令
在eclipse中运行maven 一.首先要对pom.xml文件右键→Run As→Maven build 二.输入Maven命令 三.常见的Maven命令有: [1]clean 清理 [2]comp ...
- MATLAB 动图绘制、保存
动图有gif格式和视频的avi格式. 1.sin(x)动图 clear all h = animatedline;%动画线 axis([0 4*pi -1 1]) box on x = linspac ...
- [WPF]为什么使用SaveFileDialog创建文件需要删除权限?
1. 问题 好像很少人会遇到这种需求.假设有一个文件夹,用户有几乎所有权限,但没有删除的权限,如下图所示: 这时候使用SaveFileDialog在这个文件夹里创建文件居然会报如下错误: 这哪里是网络 ...