python 中是否有将 utf-8 转换为整数的函数?

is there a function to convert utf-8 to integer in python?

有没有python函数可以将utf-8转换成int。我可以从 int 转到 utf-8,但不知道如何返回。

num = 169
a=chr(169).encode('utf-8')
print(a)
print(a.decode('utf-8'))

此代码输出:

b'\xc2\xa9'
©

我需要回到 169。谁能指导我怎么做?

使用ord()函数。

>>> ord(a.decode('utf-8'))
169

您可以使用ord函数

num = 169
a=chr(169).encode('utf-8')
print(ord(a.decode('utf-8')))