返回编译(模式、标志)时出错。findall(字符串)类型错误:应为字符串或byteslike对象

2024-04-26 11:49:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下代码:

for item in classification:
        re_item = re.findall(("var {} = \'(.*?)\'").format(item), req, re.DOTALL)[0]
        re_item = ast.literal_eval(re_item)
        for item_2 in re_item:
                category = reclassification(item)
                longitude = str(item_2['geometry']['coordinates'][0])
                latitude = str(item_2['geometry']['coordinates'][1])
                kab = item_2['properties']['kab']
                description = item_2['properties']['description']
                title = item_2['properties']['title']
                jenis = item_2['properties']['jenis']
                try:
                        rs = item_2['properties']['rs']
                except:
                        rs = ''
                kec = item_2['properties']['kec']
                tanggal = item_2['properties']['tanggal']
                umur = item_2['properties']['umur']
                container = [category, longitude, latitude, kab, kec, description, title, jenis, rs, umur, tanggal]
                output = ','.join(container)
                f.write('{}\n'.format(output))

f.close()
print('Selesai! Cek file di ./data/covid_sulsel.csv')

错误

File "C:\Users\satrio_budbud\Anaconda4\lib\re.py", line 223, in findall
  return _compile(pattern, flags).findall(string)

TypeError: cannot use a string pattern on a bytes-like object

Tags: inreformatfortitledescriptionpropertiesitem