i see a string in this code:
data[:2] == '\xff\xfe'
i don’t know what ‘\xff\xfe’ is,
so i want to escape it ,but not successful
import cgi
print cgi.escape('\xff\xfe')#print \xff\xfe
how can i get it.
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot escape or encode an invalid string.
You should understand that you are working with strings and not byte streams and there are some characters you cannot accept in them, first of them being
0x00– and also your example that is happening to be a BOM sequence.So if you need to include non-valid strings characters (unicode or ascii) you will have to stop using strings for this.
Take a look at PEP-0358