I have a value that always needs to be defined but may not always be meaningful, and I need a placeholder for when it doesn't yet have a meaningful value. Usually, I would use None as that placeholder value. For example, this code is supposed to ask for a Python literal, asking again every time the user inputs something that is not a Python literal:
import ast
user_input = None
while user_input is None:
try:
user_input = ast.literal_eval(input("Enter a Python literal: "))
except:
pass
This is one use case, but I've also used None as a placeholder in data structures, loops, and other cases.
However, None is sometimes itself a meaningful value! In the above example, the user should be allowed to input None, but they can't since that won't terminate the while loop. In other cases, they might want to store None in a tree or something similar, so I wouldn't be able to use None to represent missing values.
Since this pattern is useful in cases besides breaking out of a loop, I'm looking for a general alternative to a None in situations where a None does not work. What should I use as a placeholder value when None isn't allowed?
while True: