Метод строки isidentifier() поможет узнать, подходит ли данная строка в качестве имени объекта.
Вполне может заменить самостоятельно придуманную регулярку.
>>> 'some_name'.isidentifier()
True
Обычное имя переменной
>>> '私は手紙です'.isidentifier()
True
Юникод в качестве имени тоже доступен
>>> '1_name'.isidentifier()
False
Имя не может начинаться с цифры
>>> '੬_name'.isidentifier()
False
Включая все цифры юникода
>>> 'some name'.isidentifier()
False
Пробелы недопустимы
#basic
There’s a bird that smells like manure. The hoatzin, a bird found in the Amazon rainforest, has earned the nickname “the stinkbird.” Its digestive system ferments leaves the way cows digest grass, producing a strong manure-like smell. Because of this, predators often avoid it—not because it’s dangerous, but because it smells terrible.
@googlefactss#birds
[read more....]
The Argentine lake duck (Oxyura vittata) holds the record for the longest penis of any vertebrate relative to its body size. Males possess a corkscrew-shaped, spiny, and often-retracted organ that can measure up to 20 cm (nearly 8 inches).
@googlefactss#birds