How to validate list of UUID's AND return UUID Version?

后端 未结 2 1763
一向
一向 2021-01-16 02:06

I\'m needing to both validate a list of UUID\'s as well as determine the version. For example, using https://www.beautifyconverter.com/uuid-validator.php and entering 25CCCA

2条回答
  •  被撕碎了的回忆
    2021-01-16 02:30

    def validate_uuid4(uuid_string):
    
        try:
            val = UUID(uuid_string, version=4)
        except ValueError:
            # If it's a value error, then the string 
            # is not a valid hex code for a UUID.
            return False
    
        return True
    

    You can use the above function to go through your list of uuid string and it will tell you whether a particular string in the list if a valid version 4 uuid

提交回复
热议问题