python密钥代码和configparser帮助

时间:2014-06-01 01:49:48

标签: python python-2.7

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

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

1 个答案:

答案 0 :(得分:1)

有一个拼写错误:key应为keycode

您可以使用intchr

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