USE CONTEXT ADDED AT THE END
I often want to work with an abstract object like a list. eg.
def list_ish(thing):
for i in xrange(0,len(thing)):
print thing[i]
Now this is suitable if the thing is a list, but will fail if it is a thing, for example, a dict. what is pythonic, why ask: "Are you acting like a list?"
Note:
hasattr('__getitem__') and not hasattr('keys')
this will work for all cases that I can think of, but I don’t like to determine the type of duck negatively, since I expect that there may be cases that it does not catch.
Actually I want to ask. "Hey, you work on the whole record in how I expect the list to be?" eg.
thing[i], thing[4:7] = [...], etc.
. try/except, . , .
- " " - , , , dict-like, .
- "" - , , -
- , , .
- , , , "-", -, - - , .
- , , , , , , .
- , 'is_matrix' 'is_point_list' , . , , .
- , , , , , python.
, , , , , , Pythonistap >
kool-...