Python Forum
32 ASCII abbreviations as variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
32 ASCII abbreviations as variables
#1
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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
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']}")
Reply
#3
i have done that, except with the codes being ints.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020