TypeError: 'NoneType' object is not iterable 一次错误场景

摘要:
TypeError:'NoneType'objectisnotiterable源码defget_url(lines):urls=[]forlineinlines:if'img'inurls:url=line.split('src='http://t.zoukankan.com/)[-1].split('"')[1]urls.append(url)defoutputto(urls):count=0f

TypeError: 'NoneType' object is not iterable

源码

def get_url(lines):
    
    urls=[]
    for line in lines:
        if 'img' in urls:
            url=line.split('src='http://t.zoukankan.com/)[-1].split('"')[1]
            urls.append(url) 
    
def outputto(urls):
    count=0
    for line in urls:
        print('第{:2}个url为{}'.format(count,line))
        count=count+1

意思是urls里面的内容为空
向上找发现 上面的get_url 函数未添加return 返回值
需要在下面的函数调用,所以返回报错
运行后在for line in urls 报错
TypeError: 'NoneType' object is not iterable 一次错误场景第1张

免责声明:文章转载自《TypeError: 'NoneType' object is not iterable 一次错误场景》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇如何使用SVN添加项目qcow2镜像制作下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

iptables规则的查看、添加、删除和修改

  http://ns.35.com/?p=211 1、查看iptables -nvL –line-number -L 查看当前表的所有规则,默认查看的是filter表,如果要查看NAT表,可以加上-t NAT参数 -n 不对ip地址进行反查,加上这个参数显示速度会快很多 -v 输出详细信息,包含通过该规则的数据包数量,总字节数及相应的网络接口 –line...

关于PHP自动捕捉处理错误和异常的尝试

  之所以想着做错误和异常的自动处理是因为:     用的公司自己的框架写API,没有异常和错误相关功能,     而每次操作都进行try...catch,有点繁琐不说,感觉还很鸡肋,即使我catch到了,还是得写代码进行处理,哪怕封装了一个方法进行处理也还是繁琐,     这种情况应该是程序自动进行处理,不该是这样弱智的人工try...catch,然后处...

Idea运行报错Error running ‘Application‘: Command line is too long的解决方法

新项目再Idea里面启动的时候,有的时候报错Error running ‘Application’: Command line is too long. Shorten command line for Application or aalso for Spring Boot default configuration,报错信息如下所示 怎么解决呢,首先找...

Linux shell command line process(命令行处理流程)

Splits the command into tokens that are separated by the fixed set of metacharacters: SPACE, TAB, NEWLINE,;,(,),<,>,|, and&. Types of tokens include words, keywords,...

4.1. 如何在Windows环境下开发Python

4.1. 如何在Windows环境下开发Python 4.1. 如何在Windows环境下开发Python 4.1.1. Python的最原始的开发方式是什么样的 4.1.1.1. 找个文本编辑器,新建个.py文件,写上Python代码 4.1.1.2. 打开Windows的cmd,并且切换到对应的python脚本所在目录 4.1.1.2.1....

shell函数的调用执行

要想调用执行自己编写的shell文件中的函数,有如下方法: 比如,自己编写了一个test.sh文件如下, #===========test.sh: #! /bin/sh echo_line() {         echo date         echo "Wellcome to shell func!" } echo_line() {...