text_question_qmark.py 702 B

1234567891011121314151617181920212223242526272829
  1. from PyInquirer import prompt, Validator, ValidationError
  2. from prompt_toolkit import document
  3. import regex
  4. class NickNameValidator(Validator):
  5. def validate(self, document: document.Document) -> None:
  6. ok = regex.match('^[A-Z][a-z]+$', document.text)
  7. if not ok:
  8. raise ValidationError(message = 'Please enter a correct name, with a uppercase and letters', cursor_position = len(document.text))
  9. widget = [
  10. {
  11. 'type':'input',
  12. 'name':'nickname',
  13. 'message':'Choose a nickname :',
  14. 'qmark':'>>>',
  15. 'validate':NickNameValidator
  16. }
  17. ]
  18. try :
  19. result = prompt(widget)
  20. except ValueError :
  21. print('Pb !!!')
  22. exit()
  23. print('Your answer is')
  24. print(result["nickname"])
  25. print(type(result["nickname"]))