Python Forum
32 ASCII abbreviations as variables - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: 32 ASCII abbreviations as variables (/thread-11403.html)



32 ASCII abbreviations as variables - Skaperen - Jul-07-2018

32 ASCII abbreviations as variables assigned with their ASCII code values. this can help make code that uses ASCII control character codes more mnemonic and self documenting.
NUL,SOH,STX,ETX,EOT,ENQ,ACK,BEL,BS,TAB,NL,VTAB,FF,CR,SO,SI,DLE,DC1,DC2,DC3,DC4,NAK,SYN,ETB,CAN,EM,SUB,ESC,FS,GS,RS,US = range(32)
you might want to split up that long line.


RE: 32 ASCII abbreviations as variables - Larz60+ - Jul-07-2018

it would be much better to use a dictionary, quick, untested example:
ascii_ctrl_characters = {
    '0x00': 'NUL',
    '0x01': 'SOH',
    ...
}
# or if indexed by name:
ascii_ctrl_characters = {
    'NUL': '0x00',
    'SOH': '0x01',
    ...
}

print(f"{ascii_ctrl_characters['SOH']}")



RE: 32 ASCII abbreviations as variables - Skaperen - Jul-07-2018

i have done that, except with the codes being ints.