Last active
November 6, 2020 00:17
-
-
Save whwkong/d16a6100728d0b721329d71fc2f88b25 to your computer and use it in GitHub Desktop.
Checks if string is valid uuid4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from uuid import UUID | |
| def is_valid_uuid4(uuid_to_test): | |
| """ | |
| Check if uuid_to_test is a valid UUID, version 4. | |
| Args: | |
| uuid_to_test : str | |
| Returns: | |
| True if uuid_to_test is a valid UUID, otherwise `False`. | |
| """ | |
| try: | |
| uuid_obj = UUID(uuid_to_test, version=4) | |
| except (AttributeError, TypeError, ValueError): | |
| return False | |
| return str(uuid_obj) == uuid_to_test | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment