python 函数报错TypeError: object of type 'int' has no len()
函数源码
_times = 0
def hannuota(nlist,mfrom,mpass,mto):global _timesn=len(nlist)#n=nlist._length_if n==1:_times+=1print('%-2d'%_times,nlist[0],':',mfrom,'------>',mto)else:hannuota(nlist[:n-1],mfrom,mto,mpass)hannuota(nlist[-1],mfrom,mpass,mto)hannuota(nlist[:n-1],mpass,mfrom,mto)if __name__=='__main__':print('the process is as following:\n')print('step num:from------>to')hannuota([0,1,2],'A','B','C')
~
运行时报错:
the process is as following:step num:from------>to
('1 ', 0, ':', 'A', '------>', 'C')
Traceback (most recent call last):File "hannuota.py", line 18, in <module>hannuota([0,1,2],'A','B','C')File "hannuota.py", line 10, in hannuotahannuota(nlist[:n-1],mfrom,mto,mpass)File "hannuota.py", line 11, in hannuotahannuota(nlist[-1],mfrom,mpass,mto)File "hannuota.py", line 4, in hannuotan=len(nlist)
TypeError: object of type 'int' has no len()
问题出在“hannuota(nlist[-1],mfrom,mpass,mto)”,nlist[-1]是一个int类型。log中已经指明出错行数了。
改正后的代码为:
_times = 0
def hannuota(nlist,mfrom,mpass,mto):global _timesn=len(nlist)#n=nlist._length_if n==1:_times+=1print('%-2d'%_times,nlist[0],':',mfrom,'------>',mto)else:hannuota(nlist[:n-1],mfrom,mto,mpass)hannuota([nlist[-1]],mfrom,mpass,mto)hannuota(nlist[:n-1],mpass,mfrom,mto)if __name__=='__main__':print('the process is as following:\n')print('step num:from------>to')hannuota([0,1,2],'A','B','C')
~
运行结果:
the process is as following:step num:from------>to
('1 ', 0, ':', 'A', '------>', 'C')
('2 ', 1, ':', 'A', '------>', 'B')
('3 ', 0, ':', 'C', '------>', 'B')
('4 ', 2, ':', 'A', '------>', 'C')
('5 ', 0, ':', 'B', '------>', 'A')
('6 ', 1, ':', 'B', '------>', 'C')
('7 ', 0, ':', 'A', '------>', 'C')
python 函数报错TypeError: object of type 'int' has no len()相关推荐
- 成功解决Python中出现的TypeError: object of type 'zip' has no len()
成功解决Python中出现的TypeError: object of type 'zip' has no len() 不罗嗦,直接解决问题! 目录 解决问题 解决思路 解决方法 解决问题 TypeEr ...
- 成功解决TypeError: object of type ‘int‘ has no len()
成功解决TypeError: object of type 'int' has no len() 目录 解决问题 解决思路 解决方法 解决问题 TypeError: object of type 'i ...
- Python 3 报错 TypeError: object() takes no parameters【新手必过坑之一】
在学习 Python 3 类的时候,有如下程序: class Dog():def __init__(self,name,age):#初始化属性name和ageself.name = nameself. ...
- python2.7web代码用python3.6运行时,浏览器发送请求报错TypeError: Object of type 'bytes' is not JSON serializable的解决办法
浏览器的Cookie由Python 2代码设置.Python 3将cookie内容解释为字节字符串.只要清除浏览器cookie就好了.
- python3中调用map函数报错map object at 0x000001EF004D97B8
python3中调用map函数报错<map object at 0x000001EF004D97B8> 在python中这样的一段代码报错: a=map(int,input().split ...
- DataFrame/Series运行round()函数报错“TypeError: a float is required”解决办法
DataFrame/Series运行round()函数报错"TypeError: a float is required"解决办法 原代码片段: #把数据按年龄分层,然后按照不同层 ...
- TypeError: object of type 'zip' has no len()、'zip' object is not subscriptable
TypeError: object of type 'zip' has no len().'zip' object is not subscriptable zip 对象没有length属性不可以遍历 ...
- pandas统计文章字数:TypeError: object of type ‘float‘ has no len()
使用pandas.read_csv()读取文件, 统计文章字数时:train['text_len'] = train['text'].map(len) 报错: TypeError: object of ...
- python报错TypeError: unsupported operand type(s) for -: ‘decimal.Decimal‘ and ‘float‘的解决方法
问题描述 在编写python代码时,进行小数位相减时出现 TypeError: unsupported operand type(s) for -: 'decimal.Decimal' and 'fl ...
最新文章
- php 操作分表代码
- Linux下批量重命名文件名为数字索引编号(0~N.xxx)的方法
- Linux虚拟机基本操作
- mysql 中文 length_mysql length()中文长度一些问题整理
- 如何测量接收机到卫星的距离
- Hello World With JBoss Modules
- 在神经网络中使用辍学:不是一个神奇的子弹
- jax-rs jax-ws_极端懒惰:使用Spring Boot开发JAX-RS服务
- HBase使用场景和成功案例 (转)
- 扔盘子(51Nod-1279)
- oracle 的基本命令(一)
- LoggingFilter Session 以及Async
- 干货:react新手入门之react小书
- 基于redis实现活跃用户统计功能
- python的文件怎么删除干净_python 实现彻底删除文件夹和文件夹下的文件
- 错误:Error: Could not open client transport with JDBC Uri: jdbc:hive2://ducking:10000: java.net.Connec
- s饥荒服务器物品id,饥荒物品代码大全
- MATLAB导入数据importdata功能
- python贪吃蛇控制台_通过 PRA 的 python-pygame 玩转贪吃蛇
- oracle账户余额表和明细表,科目余额表与明细账
热门文章
- sa387gr11cl2是什么材料,sa387gr11cl2美标钢板性能介绍
- idea 2018版的无法在线下载安装插件解决方法
- 大数据技术之_20_Elasticsearch学习_01_概述 + 快速入门 + Java API 操作 + 创建、删除索引 + 新建、搜索、更新删除文档 + 条件查询 + 映射操作
- CocoStudio UI 编辑器的使用
- 治安防控平台搭建,为您打造平安社区
- Switch中的参数
- RTT and RTO
- [DAY003]考研数学极限的计算知识点与题目总结(三)
- 数据仓库主题设计及元数据设计
- JAVA实现删除文件夹和文件