Python TypeError: not enough arguments for format string
今天使用mysqldb执行query语句的时候,在执行这条语句的时候:
select PROJ, DATE_FORMAT(MAX(DATE),'%Y-%m-%') AS MAXDATE, DATE_FORMAT(MIN(DATE),'%Y-%m-%d') AS MINDATE FROM
(SELECT resource.PROJ,`day`.DATE FROM resource,`day` where resource.MAC=`day`.MAC ORDER BY PROJ) AS PROJSET GROUP BY proj
出现一下错误:
Python TypeError: not enough arguments for format string
根据错误提示顺藤摸瓜找到病症:

在python扩展包mysqldb下的cursors.py有这么一处代码写法已经过时。
原来的的写法如图:

我们只需要把
query = query % args 修改为 query = query.format(args)
总结:这个mysqldb是我在ubuntu16.04版本的linux通过apt-get install安装的,但是也出现mysqldb里一些过时的写法。
旧版本的写法基本能满足一些基本的sql的语句执行,但是像上面的sql语句里使用了max,min等mysql系统函数的同时,又
使用了data_format函数,这样query % args 就不能使用了。
另附别人的忠告:Note that the % syntax for formatting strings is becoming outdated. If your version of Python supports it
Python TypeError: not enough arguments for format string的更多相关文章
- 使用Python过程出现的细节问题:TypeError: not enough arguments for format string
今天使用字符串格式化时,遇到的一点小问题:调用这个方法解释器出错了:TypeError: not enough arguments for format string def ll(name,age) ...
- Python TypeError: not all arguments converted during string formatting ——元组tuple(a)和(a,)的区别
今天写程序,想输出一个array的shape,原程序为: print('shape of testUImatrix:%s\nStart to make testUImatrix...'%(testui ...
- TypeError: not enough arguments for format string
到一个问题,表示100% 的时候,出现这个问题. 因为python语法会认为是你需要转移符,这个时候你可以选择100%% 来表示
- 【错误】python百分号冲突not enough arguments for format string
query = "SELECT * FROM devices WHERE devices.`id` LIKE '%{}%'".format("f2333") d ...
- TypeError: not all arguments converted during string formatting
print ("So, you're 5r old, %r tall and %r heavy." % (age, height, weight)) print ("So ...
- Python 序列类型拆包 %s 和'{}'.format 的功能差异之一
>>> 1, 2, 3 #这样写成一行相当于一个元组(1, 2, 3)>>> x = 1, 2, 3>>> x(1, 2, 3)>>& ...
- TypeError: format string
先来看一段Python代码: class Negate: def __init__(self, val): self.val = -val def __repr__(self): return str ...
- 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 ...
- statsmodels.tsa.arima_model预测时报错TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'
在 python 中用 statsmodels创建 ARIMA 模型进行预测时间序列: import pandas as pd import statsmodels.api as sm df = pd ...
随机推荐
- Delphi 对泛型TList的的改进(TSimpleList)
TList 有一个比较麻烦的问题是,到底由谁来释放List中的对象或指针. 本例将释放任务教给 TSimpleList ,方便使用. 如果 TList 为于管理对象,还可以实现 AddNewOne 功 ...
- Michael Kors - Wikipedia, the free encyclopedia
Michael Kors - Wikipedia, the free encyclopedia Michael Kors From Wikipedia, the free encyclopedia ...
- 左右 android AES 所述机器的一部分 javax.crypto.BadPaddingException: pad block corrupted
好多人 android 使用上述 AES 显现 javax.crypto.BadPaddingException: pad block corrupted 下面的代码发布没问题,比较自己.不解释! p ...
- package.json配置项
以下示例列举了常用的地方,一些不常用的可以查看文档:文档地址 { //该模块名字 "name":"test" , //版本 "version" ...
- SQL学习之Insert的特殊用法(插入检索出的数据,表之间的数据复制)
1.插入检索出的数据 select * from dbo.Customers_1
- Activity之onWindowFocusChanged
public void onWindowFocusChanged (boolean hasFocus) 参数hasFocus: the window of this activity has focu ...
- Ado.net 类扩展属性
.要扩展的类名字一样,2个类加(partial) 小例子: using System; using System.Collections.Generic; using System.Linq; usi ...
- WPF-MVC开发模式简要介绍
1, 建立WPF程序,并在程序中添加三个文件View,ViewMoudle,Moudle, 2,Moudle文件加中添加类,此文件夹中存放的类基本为数据类,主要是字段和属性 3 ViewMoudle文 ...
- Android 内部存储安装apk文件实现
目前国内市场的山寨机横行,安卓手机升级也是一天一个样,对于原来老手机可能没有SDCARD,导致我们的APP不能下载资源,无法更新APP,针对这种情况有以下解决方案.通过以下函数判断是否有SD卡再判断下 ...
- Java之工厂模式
interface Fruit { void eat(); } class Apple implements Fruit { public void eat() { S ...