小编Jas*_*der的帖子

将十六进制值存储为整数

我目前正在使用 python docx,它需要十六进制值来格式化字体颜色,例如

font.color.rgb = RGBColor(0x70, 0xad, 0x47)
Run Code Online (Sandbox Code Playgroud)

然而,我需要将争论存储RGBColor在一个变量中,确切地说是一个字典,但是当您在变量中存储十六进制值时,它会将其格式化为 int 。例子:

code = (0x70, 0xad, 0x47)

print(code)
Run Code Online (Sandbox Code Playgroud)

返回:(112, 173, 71)

并使用该hex()函数存储它会将其格式化为str.

code = (hex(0x70), hex(0xad), hex(0x47))

print(code)
Run Code Online (Sandbox Code Playgroud)

返回:('0x70', '0xad', '0x47')

并且RGBColor运算符不会接受字符串,并且我无法将这些字符串重新格式化回 anint因为我收到错误ValueError: invalid literal for int() with base 10: '0x70'

在夏季,如何存储十六进制值(例如0x70, 0xad, 0x47整数),然后将其输入操作RGBColor符?

python hex python-docx

1
推荐指数
1
解决办法
565
查看次数

标签 统计

hex ×1

python ×1

python-docx ×1