-
Python学习笔记:TypeError: not all arguments converted during string formatting
2018-07-04 11:34:31TypeError: not all arguments converted during string formatting 举例 例如: >>> strs=(1,2,3,4) #创建一个集合 >>> ...前言
在学习python中难免犯下一些幼稚的错误,为了方便后来人的学习与自己的进步,整理了在学习过程中犯下的错误,写下此篇文档。
目录
问题
TypeError: not all arguments converted during string formatting
举例
例如:
strs=(1,2,3,4) #创建一个集合 strs (1, 2, 3,4) >>> print 'strs= %s ' % strs Traceback (most recent call last): File "<pyshell#43>", line 1, in <module> print 'strs= %s ' % str TypeError: not all arguments converted during string formatting
原因:1 % 操作符只能直接用于字符串(‘123’),列表([1,2,3])、元组,因此需要一一匹配操作符。
解决方法
print 'strs= %s' % (strs,) strs= (1, 2, 3,4) 也可以用: print 'strs= %s,%s,%s,%s' % sstr strs= 1,2,3,4
#简单解释
说明前后%和后面的参数数量不对应,比如File "<pyshell#37>", line 1, in <module> print '%f meters is the same as &f km' % (meters, kilometers) TypeError: not all arguments converted during string formatting
后面有miles和kilometer两个参数,前面只有一个%f,还有一个打印错的&, 前后不一致; 如果改成
print '%f miles is the same as %f km' % (miles, kilometers)
就可以了
补充
如果还有不会的,可以关注下面的公众号,博主会在24小时内回复。
-
TypeError: ‘int‘ object is not iterable
2018-09-20 16:12:28Python写循环程序的时候遇到 TypeError: ‘int’ object is not iterable,原因是循环中使用的应该是一组数,将 for i in len(A) 改成 for i in range(len(A)) 即可Python写循环程序的时候遇到 TypeError: ‘int’ object is not iterable,原因是循环中使用的应该是一组数,将
for i in len(A)
改成
for i in range(len(A))
即可
-
TypeError: string indices must be integers
2019-09-29 16:01:40Python3报错:TypeError: string indices must be integers 问题如下图所示: 原因在于for循环中的i代表String类型变量,而List中的i代表Int类型变量,二者冲突,导致出错。 ... -
Python迭代DataLoader时出现TypeError: Caught TypeError in DataLoader worker process 0.错误。
2019-11-30 22:17:06迭代DataLoader时出现TypeError: Caught TypeError in DataLoader worker process 0.错误。遇见一个难以解决的问题 遇见一个难以解决的问题 迭代 DataLoader时出现以下错误,暂时不知道怎么解决,向大家求救,是一个...Python迭代DataLoader时出现TypeError: Caught TypeError in DataLoader worker process 0.错误。
TypeError: Caught TypeError in DataLoader worker process 0.
TypeError: ‘NoneType’ object is not subscriptable
迭代
DataLoader
时出现以下错误,暂时不知道怎么解决,向大家求救,是一个比较稀罕的错误,也分享给大家一个奇葩的问题一起讨论。Traceback (most recent call last): File "/home/zero/blood_detect/PyTorch-YOLOv3/mTrain.py", line 96, in <module> for batch_i, info in enumerate(dataloader): File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 819, in __next__ return self._process_data(data) File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data data.reraise() File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/_utils.py", line 385, in reraise raise self.exc_type(msg) TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop data = fetcher.fetch(index) File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/zero/blood_detect/PyTorch-YOLOv3/utils/datasets.py", line 130, in __getitem__ img, targets = horisontal_flip(img, targets) File "/home/zero/blood_detect/PyTorch-YOLOv3/utils/augmentations.py", line 8, in horisontal_flip targets[:, 2] = 1 - targets[:, 2] TypeError: 'NoneType' object is not subscriptable
用pycharm查询过变量内容,dataloader里边的内容是没有问题的,就是迭代的时候有问题。
dataloader代码是这些
dataset = ListDataset(train_path, augment=True, multiscale=opt.multiscale_training, normalized_labels=False) dataloader = torch.utils.data.DataLoader( dataset, batch_size=opt.batch_size, shuffle=True, num_workers=opt.n_cpu, pin_memory=True, collate_fn=dataset.collate_fn, )
静待有缘人。
2019.11.30更新
TypeError: Caught TypeError in DataLoader worker process 0.解决。
解决方案:
将
num_workers
设置为0。Error
现在为Traceback (most recent call last): File "/home/zero/blood_detect/PyTorch-YOLOv3/mTrain.py", line 96, in <module> for batch_i, info in enumerate(dataloader): File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/dataloader.py", line 346, in __next__ data = self._dataset_fetcher.fetch(index) # may raise StopIteration File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/zero/anaconda3/lib/python3.7/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp> data = [self.dataset[idx] for idx in possibly_batched_index] File "/home/zero/blood_detect/PyTorch-YOLOv3/utils/datasets.py", line 130, in __getitem__ img, targets = horisontal_flip(img, targets) File "/home/zero/blood_detect/PyTorch-YOLOv3/utils/augmentations.py", line 8, in horisontal_flip targets[:, 2] = 1 - targets[:, 2] TypeError: 'NoneType' object is not subscriptable
好像意思是
info
没有下标不可迭代。2019.12.1 更新
TypeError: ‘NoneType’ object is not subscriptable. 解决。
解决方案
数据导入时少给了数据的标签,导致数据没有标签,也就没有下标。
给了标签后,上面那个
Error
也可以设置多个num_workers
了。更新
有个博主写的一个相关解决方案,感觉更详细一点,在这里贴上。
相关博客链接 -
Python错误:TypeError: 'int' object is not callable解决办法
2018-07-24 22:06:46今天在练习Python类相关的知识时遇到了一个TypeError,也就是类型错误。该错误的意思是Int型的对象是不可调用的(not callable)。 class User(): def __init__(self,name,age,number): self.name = name ... -
成功解决TypeError: a bytes-like object is required, not 'str'
2018-11-07 22:31:18成功解决TypeError: a bytes-like object is required, not 'str' 目录 解决问题 解决思路 解决方法 解决问题 TypeError: a bytes-like object is required, not 'str' 解决思路 问题出在... -
迭代DataLoader时出现TypeError: Caught TypeError in DataLoader worker process 0.TypeError: 'NoneType'...
2020-02-20 15:39:09这里的 Caught TypeError in DataLoader worker process 0.意思是多线程执行数据读取任务时,遇到了类型错误, 一般还会抛出异常如下: TypeError: 'NoneType' object is not subscriptable 说明可能没有读取到数据... -
TypeError 和 ReferenceError
2018-03-28 13:25:57ECAM-262中定义了7种错误类型,Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError。 其中 TypeError 和 ReferenceError 是经常会碰到的错误类型,在这里我们进行一个比较。 差异在... -
TypeError: Caught TypeError in DataLoader worker process 0. TypeError:'tuple' object is not callable
2020-02-28 13:37:38TypeError: Caught TypeError in DataLoader worker process 0. [2/1865] Original Traceback (most recent... -
成功解决TypeError: unhashable type: 'numpy.ndarray'
2019-05-20 20:38:26成功解决TypeError: unhashable type: 'numpy.ndarray' 目录 解决问题 解决思路 解决方法 解决问题 TypeError: unhashable type: 'numpy.ndarray' 解决思路 类型错误:不可... -
成功解决TypeError: tuple indices must be integers or slices, not str
2018-07-12 23:05:10成功解决TypeError: tuple indices must be integers or slices, not str 目录 解决问题 解决思路 解决方法 解决问题 TypeError: tuple indices must be integers or slices, not str for row in ... -
Python中报错提示:TypeError: Student() takes no arguments
2018-07-13 18:12:38Traceback (most recent call last): File "E:/learnpython/day06/15.py", line 20, in <module> tom = Student ("...TypeError: Student() takes no arguments 检查你的 def __... -
Python异常 TypeError
2019-03-20 19:32:36Python异常 TypeError抛出场景和规避方法介绍。 -
TypeError: Caught TypeError in DataLoader worker process 0. TypeError: ‘NoneType‘ object is not ...
2020-07-10 15:14:03使用pytorch进行train出现TypeError: Caught TypeError in DataLoader worker process 0. TypeError: 'NoneType' object is not sub_ 两个错误,解决办法。 第一步:分析错误原因 我们可以看到第一个错误是关于... -
成功解决TypeError: only integer scalar arrays can be converted to a scalar index
2019-03-04 11:07:18成功解决TypeError: only integer scalar arrays can be converted to a scalar index 目录 解决问题 解决思路 解决方法 解决问题 TypeError: only integer scalar arrays can be converted to a ... -
TypeError: cannot unpack non-iterable NoneType object
2019-07-18 20:09:54python报错如下: ...TypeError: cannot unpack non-iterable NoneType object 解决方法:报错的原因是函数返回值得数量不一致,查看函数返回值数量和调用函数时接收返回值的数量是不是一致,修改一致即可 ... -
Python OpenCV TypeError: integer argument expected, got float
2021-01-03 19:43:55Python OpenCV TypeError: integer argument expected, got float -
成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations'
2019-01-30 22:24:40成功解决TypeError: __init__() got an unexpected keyword argument 'n_iterations' 目录 解决问题 解决思路 解决方法 解决问题 TypeError: __init__() got an unexpected keyword argument 'n_... -
成功解决TypeError int object is not iterable
2020-05-14 20:03:07成功解决TypeError: 'int' object is not iterable 目录 解决问题 解决思路 解决方法 解决问题 TypeError: 'int' object is not iterable 解决思路 TypeError: 'int' object is not ... -
TypeError:req.body.hasOwnProperty is not a function
2019-12-26 18:08:39// true // Object.create(null) 空原型链 const obj = Object.create(null) obj.a = 1 // Uncaught TypeError: bar.hasOwnProperty is not a function console.log(obj.hasOwnProperty('a')) // 显示绑定 console.... -
TypeError系列之:TypeError: 'tuple' object is not callable.
2020-04-24 19:15:36TypeError: 'tuple' object is not callable。这又是一个typeerror。我们翻译一下这个报错信息, tuple对象是不可调用的,这是什么意思。只有可以内部有函数对象才可以调用(call)函数,而turple是一个数据类型,... -
Vue 项目打包后访问报错:Uncaught TypeError: Cannot read property 'call' of undefined
2018-05-08 15:49:10但访问的时候,有的页面可以正常访问有的页面空白并且控制台报错 Uncaught TypeError: Cannot read property 'call' of undefined,查看 network 里资源都已经成功加载,如下图: 解决办法 修改 webpack.prod.... -
Python初学者之TypeError: unhashable type: 'list'问题分析
2018-07-28 14:18:11使用Python实现机器学习k-近邻算法,创建数据集和标签时,出现了“TypeError: unhashable type: 'list'”错误,无法正确打印出group和labels。 1、错误代码与错误信息 具体代码实例如下: from numpy import * ... -
TypeError TypeError: can only concatenate str (not “NoneType“) to str
2020-08-15 21:23:56问题背景: 访问会员列表...TypeError TypeError: can only concatenate str (not “NoneType“) to str 原因在于会员的face如果为空,则访问会员列表无法取到值. 因此,我们需要在在注册的函数中给一个初始头像. ... -
Pandas 报错 :TypeError: 'numpy.ndarray' object is not callable
2018-08-27 09:55:01一般来说,TypeError: 'numpy.ndarray' object is not callable的意思是你希望通过dataframe的类对象的方法得到numpy数组。 例如博主的错误就是很典型的: known_age = age_df[age_df.Age.notnull()].values() # ... -
pytoch数据迭代器DataLoader:TypeError: Caught TypeError in DataLoader worker process 0
2020-07-02 11:19:48问题: TypeError: Caught TypeError in DataLoader worker process 0 参考网上的很多将num_works设置为0,但是一直犹豫,因为速度慢了很多,而已有没有效果也有待考证,有想试试的可以试一下 train_loader = Data.... -
Cocos creator构建游戏时报错:Build Failed: TypeError: Cannot read property ‘configs’ of null
2020-03-22 11:51:10Cocos creator构建游戏时报错:Build Failed: TypeError: Cannot read property ‘configs’ of null... 错误原因是我用版本控制管理工具的使用过程中不小心导致了项目的services.json发生了冲突,所以我直接把项目... -
TypeError: Class extends value undefined is not a constructor or null
2020-05-21 16:21:21$ vue-cli-service build ⠋ Building for production... ERROR TypeError: Class ...TypeError: Class extends value undefined is not a constructor or null at Object.<anonymous> (/root/deploy/ui/node. -
成功解决TypeError: __init__() got an unexpected keyword argument 'serialized_options'
2018-09-28 21:14:26成功解决TypeError: __init__() got an unexpected keyword argument 'serialized_options' 目录 解决问题 解决思路 解决方法 解决问题 TypeError: __init__() got an unexpected keyword argument '...
-
XSS渗透测试
-
PPT大神之路高清教程
-
NFS 实现高可用(DRBD + heartbeat)
-
C++代码规范和Doxygen根据注释自动生成手册
-
保真度与量子绝热演化之间的广义关系
-
Go-SpeedTest-Bot:帮助您使用手机管理所有节点的机器人-源码
-
【PHP】php 递归、效率和分析
-
虚幻4引擎基础
-
将和声搜索算法与杜鹃搜索混合,以进行全局数值优化
-
使用 Linux 平台充当 Router 路由器
-
RootCluster.github.io:组织网站-源码
-
XSS检测点处理
-
2021-02-25
-
通过成形InGaN / GaN纳米棒来修改远场辐射图
-
用微服务spring cloud架构打造物联网云平台
-
用于文档聚类的半监督概念分解
-
Glasterfs 分布式网络文件系统
-
HTML中的<select>标签如何设置默认选中的选项
-
沿RF锁相辅助的光纤环路链路上任意中间点的精确时延感测和工作台频率分配
-
PPTP_NNN 服务生产环境实战教程