python join/format possible hex values for regex
Question: I'd like to create a template string as possible values for an expression:

    
    
    '\x1C,\x2C,\x3C,\x4C,\x5C,\x6C,\x7C,\x8C,\x9C,\xAC,\xBC,\xCC,\xDC,\xEC,\xFC'
    

in a manner like this:

    
    
    from string import digits, ascii_uppercase
    ','.join(['\x'+i+'C' for i in digits+ascii_uppercase[:6]])
    

but unfortunately join does not treat '\x' litterally:

    
    
    SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \xXX escape
    

Unlike, for example, double slashes:

    
    
    ','.join(['\\x'+i+'C' for i in digits+ascii_uppercase[:6]])
    \\x0C,\\x1C,\\x2C,\\x3C,\\x4C,\\x5C,\\x6C,\\x7C,\\x8C,\\x9C,\\xAC,\\xBC,\\xCC,\\xDC,\\xEC,\\xFC'
    

Any ideas around this? Maybe another encoding?


Answer: Since you're dealing with characters, deal with characters.

    
    
    ','.join(chr(x) for x in range(0x1c, 0x100, 0x10))
    

