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

时间: 2024-10-30 21:27:52

Python TypeError: not enough arguments for format string的相关文章

TypeError: not enough arguments for format string

Error msg: --- Logging error --- Traceback (most recent call last): File "/usr/lib/python3.6/logging/__init__.py", line 993, in emit msg = self.format(record) File "/usr/lib/python3.6/logging/__init__.py", line 839, in format return fm

关于Python的TypeError not all arguments converted during string formatting

前言 在把yolov3的cfg文件转换为model_defs时,我忘记把str类型转换成int了,导致了一个错误,在此记录下来. 正文 如上图所示,'32'%2就是错误发生的地方. 我以为我拿到的是一个int类型的32,想判断它是偶数还是奇数. 实际上我拿到的是一个str类型的'32',这时python的解释器并没有把%理解成取余,而是理解成了这种东西. 我不知道"这种东西"的定义,但知道其用法和语法,其语法是这样的: name = 'cxy' print('%s is handsom

TypeError not all arguments converted during string formatt

1.错误描述 >>> a=1; >>> b=1; >>> for i in range(1,21): print('121d %121d' % (a,b)); if(i%3==0): a=a+b ; b=a+b; Traceback (most recent call last): File "<pyshell#23>", line 2, in <module> print('121d %121d' % (a

TypeError: not all arguments converted during string formatting

print ("So, you're 5r old, %r tall and %r heavy." % (age, height, weight)) print ("So, you're %r old, %r tall and %r heavy." % (age, height, weight)) 说明前后%和后面的参数数量不对应.红色就是错误的地方.

字符串模版替换的方法MessageFormat.format(String pattern, Object ... arguments)

MessageFormat.format(String pattern, Object ... arguments) MessageFormat.format(NewOrderConstant.PAY_SCHEMA, URLEncoder.encode(MessageFormat.format(NewOrderConstant.RESULT_SCHEME, String.valueOf(orderId)), HTTP.UTF_8), URLEncoder.encode(MessageFormat

python——TypeError: &#39;str&#39; does not support the buffer interface

import socket import sys port=51423 host="localhost" data=b"x"*10485760 #在字符串前加 b 是字符串变为bytes类. sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM) sock.connect((host,port)) byteswritten=0 while byteswritten<len(data): startpos =

String.format(String format, Object... args)方法详解

很多次见到同事使用这个方法,同时看到https://blog.csdn.net/qq_27298687/article/details/68921934这位仁兄写的非常仔细,我也记录一下,好加深印象. 这个是从java5的时候添加进去的方法. /** * Returns a formatted string using the specified format string and * arguments. * * <p> The locale always used is the one r

statsmodels.tsa.arima_model预测时报错TypeError: int() argument must be a string, a bytes-like object or a number, not &#39;Timestamp&#39;

在 python 中用 statsmodels创建 ARIMA 模型进行预测时间序列: import pandas as pd import statsmodels.api as sm df = pd.read_csv("data.csv", index_col=0, parse_dates=True) mod = sm.tsa.statespace.SARIMAX(df['price'], enforce_stationarity=False, enforce_invertibili

解决sqoop 导入oracle表时 --split-by参数为日期类型时的报错:ORA-01861: literal does not match format string

报错栈: 2017-06-08 18:46:13,422 INFO [main] org.apache.sqoop.mapreduce.db.DBRecordReader: Executing query: select "JFRQ","ZYH","FYKS","KSSE","YBJE","YPJE","ZJJE" from BSHIS."DEPCS_T_D