Sentinel object and it's applications?
<p>I know in python the builtin object() returns a sentinel object. I'm curious to what it is, but mainly it's applications. </p>

<p>Thanks.</p>

<p><code>object</code> is the base class that all other classes inherit from in python 3. There's not a whole lot you can do with a plain old object. However an object's  <em>identity</em> could be useful. For example the <a href="https://docs.python.org/3/library/functions.html#iter" rel="nofollow">iter</a> function takes a <code>sentinel</code> argument that signals went to stop termination. We could supply an object() to that.</p>

<pre><code>sentinel = object()

def step():
    inp = input('enter something: ')
    if inp == 'stop' or inp == 'exit' or inp == 'done':
        return sentinel
    return inp

for inp in iter(step, sentinel):
    print('you entered', inp)
</code></pre>

<p>This will ask for input until the user types stop, exit, or done. I'm not exactly sure when <code>iter</code> with a sentinel is more useful than a generator, but I guess it's interesting anyway.</p>

<p>I'm not sure if this answers your question. To be clear, this is just a possible application of <code>object</code>. Fundamentally its existence in the python language has nothing to do with it being usable as a sentinel value (to my knowledge).</p>

python