今天使用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. 以程序的方式操纵NTFS的文件权限

    Windows NT/2K/XP版本的操作系统都支持NTFS格式的文件系统,这是一个有安全性质的文件系统,你可以通过Windows的资源管理器来设置对每个目录和 文件的用户访问权限.这里我就不对NTF ...

  2. C++ Placement New

    先看一个题目: #include <stdio.h> #include <iostream> using namespace std; struct Base { int j; ...

  3. CF 293 E Close Vertices (树的分治+树状数组)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题目:给出一棵树,问有多少条路径权值和不大于w,长 ...

  4. stl之map 排序

    排序问题,STL中默认是采用小于号来排序的,因为设置int等类型做key,它本身支持小于号运算,在一些特殊情况,比如关键字是一个结构体,涉及到排序就会出现问题,因为它没有小于号操作,insert等函数 ...

  5. Ninject简介(转)

    1.为什么要用Ninject? Ninject是一个IOC容器用来解决程序中组件的耦合问题,它的目的在于做到最少配置.其他的的IOC工具过于依赖配置文件,需要使用assembly-qualified名 ...

  6. English - even though和even if用法解析

    even though和even if的用法区别两者均可用于引导让步状语从句,其细微区别是: 1. even if 引导的从句是往往是假设性的,相当于汉语的“即使”“纵然”“就算”“哪怕”. 如:Th ...

  7. hadoop 配置文件注意问题

    一定要配置成hostname形式: 如伪分布:配成localhost:9000 完全分布:配成big1:9000

  8. 块对象block小结(2)

    MRC环境下 ////  main.m//  blcok////  Created by ios on 16/4/6.//  Copyright © 2016年 ios. All rights res ...

  9. memcached与redis

    Memcached VS Redis 问题:memcached 与 redis 哪个好? 答:这个问题它依赖与工程类别和它的数据. 1.它们都是内存 key/value 类型的高速与高可用的查询表. ...

  10. 我的Fedora22美化日记

    首先我说一下,我命令是乱打的[不要打我],用之前先google 配置RPMFusion仓库 $ sudo dnf install --nogpgcheck http://download1.rpmfu ...