Python-TypeError: not all arguments converted during string formatting
Where?
运行Python程序,报错出现在这一行 return "Unknow Object of %s" % value
Why?
%s 表示把 value变量装换为字符串,然而value值是Python元组,Python中元组不能直接通过%s 和 % 对其格式化,则报错
Way?
使用 format 或 format_map 代替 % 进行格式化字符串
出错代码
def use_type(value):
if type(value) == int:
return "int"
elif type(value) == float:
return "float"
else:
return "Unknow Object of %s" % value if __name__ == '__main__':
print(use_type(10))
# 传递了元组参数
print(use_type((1, 3)))
改正代码
def use_type(value):
if type(value) == int:
return "int"
elif type(value) == float:
return "float"
else:
# format 方式
return "Unknow Object of {value}".format(value=value)
# format_map方式
# return "Unknow Object of {value}".format_map({
# "value": value
# }) if __name__ == '__main__':
print(use_type(10))
# 传递 元组参数
print(use_type((1, 3)))
Python-TypeError: not all arguments converted during string formatting的更多相关文章
- 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 all arguments converted during string formatting
print ("So, you're 5r old, %r tall and %r heavy." % (age, height, weight)) print ("So ...
- Python TypeError: not enough arguments for format string
今天使用mysqldb执行query语句的时候,在执行这条语句的时候: select PROJ, DATE_FORMAT(MAX(DATE),'%Y-%m-%') AS MAXDATE, DATE_F ...
- 'not all arguments converted during string formatting'错误告警信息解决办法
问题描述:
- 使用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百分号冲突not enough arguments for format string
query = "SELECT * FROM devices WHERE devices.`id` LIKE '%{}%'".format("f2333") d ...
- 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 ...
- pywinauto: 导入时遇到 "TypeError: LoadLibrary() argument 1 must be string, not unicode"
pywinauto: 导入时遇到 "TypeError: LoadLibrary() argument 1 must be string, not unicode" 经查询, 看到 ...
随机推荐
- 在使用postman中操作api接口测试403解决方法
在向Jenkins发送请求时收到了这样的403错误信息: No valid crumb was included in the request 后来通过google找到了解决方案. http://st ...
- Vue 开发技巧总结
博客地址:https://ainyi.com/95 本人玩了 Vue 两年多,在此总结一下开发时的一些技巧和方法 自定义组件 v-model v-model 是 Vue 提供的一个语法糖,它本质上是 ...
- 医疗seo常用的图标工具
http://www.wocaoseo.com/thread-304-1-1.html 下面是一些医疗seo常用的一些图表工具,这些都是些最简单的工具,主要放置这里以防止以后有作用. 1,医疗的常用搜 ...
- 安装Apache所踩的的坑
刚开始接触PHP等一些脚本语言,需要建立一个本地的服务器,变进行安装了Apache.在其中碰到了诸多问题,和大家一一分享一下. 一.刚解压完成后使用cmd面板进入解压完成的apache的bin目录下, ...
- amd、cmd、CommonJS以及ES6模块化
AMD.CMD.CommonJs.ES6的对比 他们都是用于在模块化定义中使用的,AMD.CMD.CommonJs是ES5中提供的模块化编程的方案,import/export是ES6中定义新增的 什么 ...
- 沉珂日重的Java项目 Spring真的帮到我们了吗?
开局三连图. 这是刚开始时的程序结构,虽清晰已经有混乱的前兆. 业务增加,人员增加后就会沉珂日重. 几年后,最后的模样会让使用者和维护者都很无奈. 人们喜欢把Java程序的层次结构比作建筑,实际却最像 ...
- Openresty使用
OpenResty是一个全功能的 Web 应用服务器.它打包了标准的 Nginx 核心,常用的第三方模块以及大多数依赖项. 可以把它看成是Nginx附加众多的第三方插件的合集.其主体是嵌入lua脚本的 ...
- Bypass windous/mac 登陆密码
前言 如题,在52破解里看到一个非常好用的工具 Kon-Boot 2.7 功能 不会去擦除windows密码 不会修改windows文件 此外,Kon-Boot的最新版是目前世界上唯一的一个能够绕过W ...
- 第16课 - make的隐式规则(下)
第16课 - make的隐式规则(下) 1
- [HDOJ1232]畅通工程(并查集)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1232 题目描述 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表, ...