LINUX.ORG.RU

История изменений

Исправление ptah_alexs, (текущая версия) :

import io
import os
import sys
import re

def read_data(name):
    with open(name,'r') as fin:
        return fin.readlines()

def write_data(name, data):
    with open(name,'w') as fout:
        fout.writelines(data)

def main():
    ed = []
    data = read_data('data.txt')
    data1 = str(data[0])[1:-2]
    flist = data1.split(', ')
    for el in flist:
        dstr = el.strip()
        ed.append(re.sub("\<\/td\>\<td.*?\>",",",dstr)+'\n')
    write_data('end_data.txt',ed)

if __name__ == "__main__":
    main()

Исправление ptah_alexs, :

import io
import os
import sys
import re

def read_data(name):
    with open(name,'r') as fin:
        return fin.readlines()

def write_data(name, data):
    with open(name,'w') as fout:
        fout.writelines(data)

def main():
    ed = []
    data = read_data('data.txt')
    data1 = str(data[0])[1:-2]
    flist = data1.split(', ')
    for el in flist:
        dstr = el.strip()
        ed.append(re.sub("\<\/td\>\<td.*\>",",",dstr)+'\n')
    write_data('end_data.txt',ed)

if __name__ == "__main__":
    main()

Исходная версия ptah_alexs, :

import io
import os
import sys
import re

def read_data(name):
    with open(name,'r') as fin:
        return fin.readlines()

def write_data(name, data):
    with open(name,'w') as fout:
        fout.writelines(data)

def main():
    ed = []
    data = read_data('data.txt')
    data1 = str(data[0])[1:-2]
    flist = data1.split(', ')
    for n, el in enumerate(flist):
        dstr = el.strip()
        ed.append(re.sub("\<\/td\>\<td.*\>",",",dstr)+'\n')
    write_data('end_data.txt',ed)

if __name__ == "__main__":
    main()