今天使用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的更多相关文章

  1. 使用Python过程出现的细节问题:TypeError: not enough arguments for format string

    今天使用字符串格式化时,遇到的一点小问题:调用这个方法解释器出错了:TypeError: not enough arguments for format string def ll(name,age) ...

  2. Python TypeError: not all arguments converted during string formatting ——元组tuple(a)和(a,)的区别

    今天写程序,想输出一个array的shape,原程序为: print('shape of testUImatrix:%s\nStart to make testUImatrix...'%(testui ...

  3. TypeError: not enough arguments for format string

    到一个问题,表示100% 的时候,出现这个问题. 因为python语法会认为是你需要转移符,这个时候你可以选择100%% 来表示

  4. 【错误】python百分号冲突not enough arguments for format string

    query = "SELECT * FROM devices WHERE devices.`id` LIKE '%{}%'".format("f2333") d ...

  5. TypeError: not all arguments converted during string formatting

    print ("So, you're 5r old, %r tall and %r heavy." % (age, height, weight)) print ("So ...

  6. Python 序列类型拆包 %s 和'{}'.format 的功能差异之一

    >>> 1, 2, 3 #这样写成一行相当于一个元组(1, 2, 3)>>> x = 1, 2, 3>>> x(1, 2, 3)>>& ...

  7. TypeError: format string

    先来看一段Python代码: class Negate: def __init__(self, val): self.val = -val def __repr__(self): return str ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. openssl编译(VC6.0)

    官网:http://www.openssl.org/ 得到源码: git clone  https://github.com/openssl/openssl 一.用vc编译器编译: 1.下载nasm: ...

  2. 解决:未能加载文件或程序集“Newtonsoft.Json, Version=4.5.0.0

    开发环境:Microsoft Visual Studio 2013 MVC4.0 使用SignalR的过程中随着版本的升级,其它程序集也跟着升级,如Newtonsoft.Json,一般编译的时候,如果 ...

  3. MYSQL 巧用count,sum进行统计数据

    SELECT a.user,count(b.order_id) as subcount,sum(if(b.verifysta='Y',1,0)) as passcount FROM vicidial_ ...

  4. 《Linux 设备驱动程序》读后感。 并发,竞态,死锁。

    1. 概念 并发:在操作系统中,是指一个时间段中有几个程序都处于已启动运行到运行完毕之间,且这几个程序都是在同一个处理机上运行,但任一个时刻点上只有一个程序在处理机上运行. 来源: 1. Linux ...

  5. golang win32编程的一个dll坑

    例子 package main import ( "github.com/lxn/win" "strconv" "syscall" ) fu ...

  6. #include <map>

    //tuple多元数组,必须是静态数组,类似结构体 //配合array,vector使用 //std::tuple<数组元素类型>数组变量名(数组元素变量名); #include < ...

  7. 请问下mtk双卡手机怎样发短信是怎样选择sim卡来发(双卡都可用的情况下)?

    如题,我如今可以获取双卡状态,当仅仅有单一卡的时候可以指定sim卡进行发短信,可是双卡都可用的情况下,程序就默认使用卡1发短信了.即使指定了sim卡编号.

  8. libcurl使用示例

    远程下载文件,并将http 头信息存放内存中以及文件大小等相关信息: #include <stdio.h> #include <curl/curl.h> #include &l ...

  9. MyEclipse 2013 导入MyEclipse 9.0的EJB项目时,需要注意

    点击“next”按钮,出现下面的对话框: 再点击“next”按钮,出现下面的对话框:

  10. WinForm中快捷键与组合按键的设置方法

    每个窗体都有这样3个事件:KeyDown.KeyPress.KeyUp,KeyDown和KeyPress都是按键按下事件,但KeyDown用的是KeyCode跟键盘各个按键相对应,它对应Keys枚举, ...