After extracting Chinese content from a file, Python2.7 uses rules to find some information. Why does it prompt None?

topic description

you need to query a paragraph of text in the file

sources of topics and their own ideas

related codes

import re

data = ["2017-9-30"]
file = open(u".txt", "r")
key = file.read().decode("gbk")
print key
p1 = r""
pattern = re.compile(p1)
matcher = re.search(pattern,key)
data.append(matcher)
print data

what result do you expect? What is the error message actually seen?

< H1 > current results: < / H1 >

1. The operating income of the company from January to September 2017, the net profit attributable to the owner of the parent company and the net profit attributable to the owner of the parent company after deducting non-recurring profits and losses were 987.6899 million yuan, 140.7998 million yuan and 136.49 million yuan respectively, up 10.27%, 35.63% and 20.30% from January to September 2016, respectively, reflecting the good operation of the company.
2. The main reasons for the company"s higher management expenses in 2017 than in 2014 and lower management expenses in 2016 are as follows: 1 in March 2015, the company"s registered capital increased from US $79 million to US $91.61256 million, and the new shareholders Ningbo Lingqi, Ningbo Lingxin and Ningbo Lingxi are the employee shareholding platforms of the company, according to the company"s December 2014
["2017-9-30th, None]

. < H1 > ideal result: < / H1 >

["2017-9-30", "operating income"]

Apr.02,2021

try replacing data.append (matcher) with data.append (matcher.group (0))

I don't know if it's good to write your rule like this.

complete code:

import re

data = ['2017-9-30']
key  = """
1.20171-998,768.9914,079.9813,649.0020161-910.27%35.63%20.30%,
2.2015201420162015:201537,900.009,161.256201412
"""
print (key)
p1 = r""
pattern = re.compile(p1)
matcher = re.search(pattern,key)
data.append(matcher.group(0))
print (data)

output

1.20171-998,768.9914,079.9813,649.0020161-910.27%35.63%20.30%,
2.2015201420162015:201537,900.009,161.256201412

['2017-9-30', '']
Menu