Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 Python 中用 uuid 替换正则表达式搜索的最优雅的方法是什么?
re.sub(r'guid="([0-9a-f-]{36})"', uuid1(), contents)
由于此错误,上述语句失败:
TypeError: object of type 'UUID' has no len()
这是否适合探索 lambda 的使用?
uuid.uuid1()返回一个uuid.UUID对象。的第二个参数re.sub需要一个可调用的或一个字符串。在这种情况下,转换uuid1()为字符串str(uuid1())::
uuid.uuid1()
uuid.UUID
re.sub
uuid1()
str(uuid1())
re.sub(r'guid="([0-9a-f-]{36})"', str(uuid1()), contents)