Python converts Javascript % u string to pythonunicode

Source: Internet
Author: User
This article mainly introduces python code for converting Javascript % u string to pythonunicode. For more information, see the data collected by the web as % u6B63 % u5F0F % u4EBA % u5458, you need to read and convert it to a python object. if you want to skip Javascript to eval, you can only translate it yourself.

Core code:

Import reimport codecspattern = re. compile ('% u [0-9A-Z] {4}') n = codecs. open ('d: \ new.txt ', 'W', 'utf-8') with open ('d: \ P', 'r') as f: for l in f: for I in pattern. findall (l): l = l. replace (I, unichr (int (I [2:], 16) n. write (l) n. close ()


For more articles about how to convert the Javascript % u string to python unicode, refer to the Chinese PHP website!

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.