import string
formatter = string.Formatter()
def is_formattable(s: str):
for e in formatter.parse(s):
if isinstance(e[1], str):
return True
return False
print(is_formattable("Hello")) # False
print(is_formattable("{{}}")) # False (Double escape)
print(is_formattable("{}")) # True
print(is_formattable("{}{}")) # True
print(is_formattable("{a}{b}{c}")) # True
print(is_formattable("{a:int}")) # True
Recommended Posts