how can i check whether a variable is iterable in my code?

Aidan aidan at gmail.com
Sat Sep 20 12:35:52 CEST 2008


satoru wrote:
> hi, all
> i want to check if a variable is iterable like a list, how can i
> implement this?

this would be one way, though I'm sure others exist:

if hasattr(yourVar, '__iter__'):
	# do stuff



More information about the Python-list mailing list