簡體   English   中英

python鍵碼和configparser協助

[英]python key codes and configparser assistance

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

您可以使用intchr來獲取chr

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM