with open('utf8.txt') as f:
    class_name = 'aaa'
for line in f:
    if line == '\n':
        classname = 'bbb'
else:
    line = '<p class="{0}">{1}</p>\n'.format(class_name, line.rstrip())
Замена нескольких регулярных выражений Python