"# 获取UUID\nimport uuid\n\n\ndef get_uuid():\n return str(uuid.uuid1()).replace('-', '').upper()\n\n\ndef test():\n id = get_uuid()\n token = get_uuid()\n print(id)\n print(token)\n\nprint(test())\n如何让这个两个uuid不同内容:可以在获取第一个UUID后,再次调用获取第二个UUID的函数,确保两次获取的UUID不同。具体实现如下:\n\npython\nimport uuid\n\n\ndef get_uuid():\n return str(uuid.uuid1()).replace('-', '').upper()\n\n\ndef test():\n id1 = get_uuid()\n id2 = get_uuid()\n while id2 == id1: # 如果两个UUID相同,则重新获取第二个UUID\n id2 = get_uuid()\n token = get_uuid()\n print(id1)\n print(id2)\n print(token)\n\n\ntest()\n\n\n这样就能确保第一个UUID和第二个UUID不同。\n

Python 生成唯一 UUID 并确保不同 - 代码示例

原文地址: https://www.cveoy.top/t/topic/pTJ3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录