Python input () keyboard input 8583 messages with \x SLR Slash auto-escaping problem solving method

Source: Internet
Author: User

The string entered with input () is a 8385 message such as: \x30\x30\x30\x30 ... , but after the input, the code adds a \, like \\x30, to the 8583 message string.

But I commented out the input () code, wrote 8583 messages in the variable to die, there is no problem, I think it should be caused by coding problems.

Input inputs and variables are fixed, is there anything different?

The code is as follows:

The input of the SLR slash, is automatically escaped by the system double backslash \\x, the code adds the basis to judge:
1 if " \\x "  in INPUT_A1:

Adding decode ("Unicode_escape") solves the problem when input () keyboard is entered.

The code is as follows:

1 #Coding:utf-82 3 #fixed 8583 message 16 binary data4A ="\x31\x31\x39\x39\x30\x36\x30\x30\x30\x32\x30\x30"5 Print(Type (a))6 Print(a)7b =Str (a)8 Print("variable-->%s"%b)9 Ten  One #8583 message 16 binary data copied via the keyboard A #\x31\x31\x39\x39\x30\x36\x30\x30\x30\x32\x30\x30 -Input_a = Raw_input ("input 1->:"). Decode ("Unicode_escape") - if "\\x" inchinput_a: the     Print("the input of the SLR slash, is automatically escaped by the system double backslash \\x") - Else : -     Print("using the Unicode_escape Storage Memory value method, the 8583 message of the input SLR slash is not escaped") -     Print(Type (input_a)) +b =Str (input_a) -     Print("keyboard-->%s"%b) +      A #Check the problem atINPUT_A1 = Raw_input ("input 2->:") - if "\\x" inchINPUT_A1: -     Print("the input of the SLR slash, is automatically escaped by the system double backslash \\x") - Else : -     Print(Type (input_a)) -b =Str (input_a) in     Print("keyboard-->%s"%b

Baidu has some information, our data string is usually the str, Unicode type, basically is directly stored in the way, there is a way to store the memory encoded by the string, it is to read the string and then reverse back.

1>>> u'Chinese test'. Encode ('Unicode-escape')2 '\\u4e2d\\u6587\\u6d4b\\u8bd5'3 4>>>'\\u4e2d\\u6587\\u6d4b\\u8bd5'. Decode ('Unicode-escape')5U'\u4e2d\u6587\u6d4b\u8bd5'

Python input () keyboard input 8583 messages with \x SLR Slash auto-escaping problem solving method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.