код:
import numpy as np
import re
from tabulate import tabulate
file_input = open("4.txt", mode = 'r', encoding = 'utf-8')
file_output = open("5.txt", mode = 'w')
RegularExpressionName = r'([А-Я][а-я]+)'
RegularExpressionClass = r'([0-9]{1,3})'
RegularExpressionAge = r'(?:100|[1-9]\d|[6-9])'
RegularExpressionHeight = r'([0-9]{1,3})'
for line in file_input:
match = re.search(RegularExpressionName, line)
match1 = re.search(RegularExpressionClass, line)
match2 = re.search(RegularExpressionAge, line)
match3 = re.search(RegularExpressionHeight, line)
if match is not None:
file_output.write(match.group(0) + "," + match1.group(0) + "," + match2.group(0) + "," + match3.group(0) + '\n')
else:
file_output.write("None")
file_output.close()
def printData(arData):
print(tabulate(arData, headers=['Name', 'Class', 'Age', 'Height'],
tablefmt='github'))
arData = np.array(np.loadtxt("5.txt", delimiter=',', encoding='utf-8', dtype='str'))
print('Таблица:')
printData(arData)
file_input.close()
ОШИБКА: ругается на 19 строку и пишет что не существует аттрибута group. Но как тогда сделать без него?