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" 经查询, 看到 ...
 
随机推荐
- (数据科学学习手札94)QGIS+Conda+jupyter玩转Python GIS
			
本文完整代码及数据已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 QGIS随着近些年的发展,得益于其开源免费 ...
 - 求求大厂给个Offer:Map面试题
			
前言 文本已收录至我的GitHub:https://github.com/ZhongFuCheng3y/3y,有300多篇原创文章,最近在连载面试系列! 我,三歪,最近开始写面试系列.我给这个面试系列 ...
 - mybatis批量添加数据的三种方式
			
原文地址:https://www.cnblogs.com/gxyandwmm/p/9565002.html
 - springboot文件上传(可单文件/可多文件)
			
获取文件内容,是从InputStream中获取,添加到指定位置的文件 如下所示 public static void getFile(InputStream is,File fileName) thr ...
 - Python全局变量的简单使用
			
对Pyhon实现静态变量全局变量的方法详解 python不能像C++一样直接定义一个static变量或者通过extern来导入别的库的变量而实现数据共享,但是python的思想是通过模块化来解决这个问 ...
 - Kubernetes K8S之资源控制器Daemonset详解
			
Kubernetes的资源控制器Daemonset详解与示例 主机配置规划 服务器名称(hostname) 系统版本 配置 内网IP 外网IP(模拟) k8s-master CentOS7.7 2C/ ...
 - The Unique MST(最小生成树的唯一性判断)
			
Given a connected undirected graph, tell if its minimum spanning tree is unique. Definition 1 (Spann ...
 - B - The Staircases (dp)
			
One curious child has a set of N little bricks. From these bricks he builds different staircases. St ...
 - Life is not the amount of breath you take.
			
It's the moments that take you breath away.
 - [LeetCode]Sql系列2
			
题目 1205. 每月交易II Transactions 记录表 +----------------+---------+ | Column Name | Type | +-------------- ...