python: how to convert a valid uuid from String to UUID?

前端 未结 3 688
花落未央
花落未央 2021-02-03 16:47

I receive the data as

   {
        \"name\": \"Unknown\",
        \"parent\": \"Uncategorized\",
        \"uuid\": \"06335e84-2872-4914-8c5d-3ed07d2a2f16\"
             


        
3条回答
  •  攒了一身酷
    2021-02-03 17:41

    Just pass it to uuid.UUID:

    import uuid
    
    o = {
        "name": "Unknown",
        "parent": "Uncategorized",
        "uuid": "06335e84-2872-4914-8c5d-3ed07d2a2f16"
    }
    
    print uuid.UUID(o['uuid']).hex
    

提交回复
热议问题