What is the class of myobj?
Mark McEahern
marklists at mceahern.com
Wed Oct 16 08:08:38 EDT 2002
[Erik Max Francis]
> It usually isn't. When you're expecting a sequence type is a good
> example, because there are some basic builtin sequence types (tuples and
> lists), but there's also builtin functions which generate objects that
> _act_ like builtin sequence types (for instance, the return value of
> xrange or F.xreadlines), and of course there are user-defined sequence
> types.
And then there are strings, which are also sequence like--but you don't
always want to iterate through them.
E.g.,
def make_list(x):
"""
Return x as a list. If x is already a list or sequence type, return x.
"""
# Obviously, I'm missing user-defined sequence types.
sequence_types = (list, tuple)
if not isinstance(x, sequence_types):
l = [x]
else:
l = x
return l
// m
-
More information about the Python-list
mailing list