Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python : TypeError: 'NoneType' object is not subscriptable

I have this list :

print(new_list)

Output :

[<None></None>]
[<None></None>, <img border="0" data-original-height="855" data-original-width="1885" src="https://1.bp.blogspot.com/-mq2ilVOcyPQ/X70khVD9UaI/AAAAAAAArLw/xC2LggPdcRUTm3aTGpPFYhoM6rDJwbyzACLcBGAsYHQ/s16000-rw/ssc-admit-card.webp"/>]
[<None></None>]

When trying to loop :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 for p in new_list:
    print(p['src'])

Getting this error :

TypeError: 'NoneType' object is not subscriptable

How to loop and get the items without the error ?

>Solution :

Don’t try to print the Nones, and only print the elements with a 'src' attribute.

for p in new_list:
    if p and p['src']:
        print(p['src'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading