gpt4 book ai didi

python 关键代码和 configparser 帮助

转载 作者:太空宇宙 更新时间:2023-11-03 18:21:47 24 4
gpt4 key购买 nike

python 2.7我如何从我的文件中获取关键代码而不是字符串

我的文件是settings.ini

[Settings]
keycode = 0x36

这是我的代码的一部分

config = ConfigParser.RawConfigParser()
config.read('settings.ini')
key = config.get('Settings', 'keycode') # this is the key code i want ---> 0x36

例如

shell.sendkeys(key)

在这种情况下,senkeys 将发送

>> 0x36

我希望它发送这个

>> 6

重要的是我不需要字符串!

最佳答案

有一个拼写错误:key 应该是 keycode

您可以使用 int 获取角色, chr :

>>> key = '0x36'
>>> int(key, 16) # Conver the string to int
54
>>> chr(int(key, 16)) # to character
'6'

关于python 关键代码和 configparser 帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23976073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com