Python 3 detect and prevent TypeError-s

Published: 16 September 2018
on channel: Softhints - Python, Linux, Pandas
1,790
7

Python detect and prevent TypeError: sequence item 0 and join iterable

https://blog.softhints.com/python-det...

Errors:

* TypeError: sequence item 0: expected str instance, int found

and

* TypeError: can only join an iterable

Option 1

import collections
mylist = 2
if isinstance(mylist, collections.Iterable):
print(', '.join(mylist))

Option 2

try:
iterator = iter(mylist)
except TypeError:
print('not iterable')
else:
print(', '.join(mylist))


On this page of the site you can watch the video online Python 3 detect and prevent TypeError-s with a duration of hours minute second in good quality, which was uploaded by the user Softhints - Python, Linux, Pandas 16 September 2018, share the link with friends and acquaintances, this video has already been watched 1,790 times on youtube and it was liked by 7 viewers. Enjoy your viewing!