Python matches special symbols in CSV file such as high-risk black block

Source: Internet
Author: User

Symbols must be saved in Unicode, and can be matched according to Unicode code.

Special characters in 1.csv can be found in the Excel caret, and the Unicode code for the symbol is noted. For example, this solid square Unicode code is 25a0:

2. Need to query other code can be based on this Code search, (of course, this example with the word code): such as Unicode 25a0 python, you can get the code in each encoding method, this example URL:

Http://www.fileformat.info/info/unicode/char/25a0/index.htm looking for Python is:

UTF-8 (hex) 0xe2 0x96 0xA0 (e296a0)
UTF-8 (binary) 11100010:10010110:10100000
UTF-16 (hex) 0x25a0 (25A0)
UTF-16 (decimal) 9,632
UTF-32 (hex) 0x000025a0 (25A0)
UTF-32 (decimal) 9,632
C/c++/java Source Code "\u25a0"
Python Source Code U "\u25a0"

3.

#-*-Coding:utf-8-*-import rea=u "\u25a0" b=u "high Risk" d= "%s%s"% (A, b) d1=d.encode (' GBK ') #decode to match text to get content, formerly utf8p= Re.compile (". *\s*%s\s*.*"%d1) with open ("B.csv", "R") as R: for    I in R:    #print I    Line=i.strip (). Split ("#") [ 7]    Print line    if P.search (line):    count+=1print "Count =%s"%count

You also need to learn the coding method carefully: http://python.jobbole.com/86670/

Python matches special symbols in CSV file such as high-risk black block

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.