OTOH, None is very often used now as a kind of "null pointer", and from
that viewpoint it's a feature that using the None object in most contexts
reliably triggers a runtime error. E.g., in your scenario I would like
to reserve a None return value to mean something like "I know I usually
return a list, but in this case I just can't, and you're really screwed
if you called me believing this wasn't a possibility".
So if None didn't exist, we'd have to invent it <wink>.
A new (different) symbol would be OK, though. How about this one?
class _NONEclass:
def __repr__(self):
return 'NONE'
def __len__(self):
return 0
def __getslice__(self,i,j):
return NONE
def keys(self):
return NONE
def items(self):
return NONE
NONE = _NONEclass()
Then "for x in NONE: ...", NONE.keys(), NONE[i:j], etc are well-defined
nops. Add more do-nothing methods to taste.
none-sense-ly y'rs - tim
Tim Peters tim@ksr.com
not speaking for Kendall Square Research Corp