escaping - How to pass escape sequences to python's ord() function? -


i using python 3. using ord() function in script. if type ord('\xff') in console returns 255

is there way insert \xff (which stored in variable) ord() function without getting

error: typeerror: ord() expected character, string of length 4 found 

how ord('\xff') work? ord() doesn't read strings? whats reading then?

are receiving data user input? in case, meant read single character read literally string of size 4.

in [1320]: v = input() \xff  in [1321]: v out[1321]: '\\xff' 

one workaround use ast.literal_eval:

in [1326]: import ast  in [1327]: v = ast.literal_eval('"{}"'.format(v))  in [1329]: ord(v) out[1329]: 255 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -