Is there a way to define list(obj) method on a user defined class in python? -
one can can implement method __str__(self) return string. there __list__(self) counterpart? (__list__ doesn't work!) .tolist() way go?
there no direct counterpart, list() implemented iterating on argument. implement either the iterator protocol (__iter__()) or bound indexing (__len__() , __getitem__()).
Comments
Post a Comment