Defining my own None-like Python constant

I don’t see anything particularly wrong with your implementation. however, 1 isn’t necessarily the best sentinel value as it is a cached constant in Cpython. (e.g. -1+2 is 1 will return True). In these cases, I might consider using a sentinel object instance:

NotInFile = object()

python also provides a few other named constants which you could use if it seems appropriate: NotImplemented and Ellipsis come to mind immediately. (Note that I’m not recommending you use these constants … I’m just providing more options).

Leave a Comment