import os
import codecs
from sys import platform as _platform


def main():
    """Конвертер файлов импорта формата ibank2 в формат CSV"""
    folder_in = 'in'
    folder_out = 'out'
    folder_out_dct = folder_out + "/dct"
    if not os.path.exists("out"):
        os.mkdir(folder_out)
    if not os.path.exists("out/dct"):
        os.mkdir(folder_out_dct)

    files = os.listdir(folder_in)

    for fl in files:
        path_to_file = os.path.join(folder_in, fl)
        name, extension_in = fl.rsplit('.', 1)
        if extension_in == "txt":
            converter(name, folder_out, folder_out_dct)

    # Открыть в проводнике ОС
    if _platform == "linux" or _platform == "linux2":
        # Требует наличия xdg-open
        os.system('xdg-open "%s"' % folder_out)
    elif _platform == "darwin":
        os.system('open "%s"' % folder_out)
    elif _platform == "win32":
        os.startfile(folder_out)


def converter(name, folder_out, folder_out_dct):
    f = codecs.open('in/' + name + '.txt', 'r', "cp1251")
    lines = f.readlines()
    print(lines)

    # f = open('in/' + name + '.txt', 'r')
    #
    # lines = f.readlines()
    print(lines[0][:-1])
    before_text1 = lines[0][:-1]

    dict_file = open(folder_out_dct + "/" + name + "." + "dct", 'w')
    csv_file = open(folder_out + "/" + name + "." + "csv", 'w')

    before_text2 = '''Data-Type=dct
Import-Format=csv
First-String-Read=true

'''
    dict_file.write(before_text1)
    dict_file.write(before_text2)

    i = 0
    for line in lines[2:]:
        data = line.split("=", 1)
        dict_file.write(data[0] + "=" + "${" + str(i) + "}" + "\n")

        if data[1].find('"') != -1:
            csv_data = '"' + data[1][:-2].replace('"', '""') + '"' + ";"
            csv_file.write(csv_data)
        else:
            csv_file.write(data[1][:-2] + ";")
        i += 1

    f.close()
    dict_file.close()
    csv_file.close()


if __name__ == '__main__':
    main()
@@ -955,16 +955,36 @@
 t_dct):%0A
+    delimiter = ';'%0A
     f = 
@@ -1062,25 +1062,8 @@
 es()
-%0A    print(lines)
 %0A%0A  
@@ -1141,33 +1141,8 @@
 s()%0A
-    print(lines%5B0%5D%5B:-1%5D)%0A
     
@@ -1456,16 +1456,116 @@
 text2)%0A%0A
+    # %D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC %D1%80%D0%B0%D0%B1%D0%BE%D1%82%D0%B0%D0%B5%D1%82 %D0%B4%D0%BB%D1%8F %D0%BE%D0%B4%D0%BD%D0%BE%D0%B3%D0%BE %D0%B4%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D0%B0 %D0%BD%D0%B0 %D0%B8%D0%BC%D0%BF%D0%BE%D1%80%D1%82, %D0%BD%D0%B5 %D0%BE%D0%B1%D1%80%D0%B0%D0%B1%D0%B0%D1%82%D1%8B%D0%B2%D0%B0%D0%B5%D1%82 %D1%81%D0%BB%D1%83%D1%87%D0%B0%D1%8F %D0%BD%D0%B0%D0%BB%D0%B8%D1%87%D0%B8%D1%8F %D0%BF%D1%83%D1%82%D1%81%D1%8B%D1%85 %D1%81%D1%82%D1%80%D0%BE%D0%BA%0A
     i = 
@@ -1695,25 +1695,24 @@
 + %22%5Cn%22)%0A
-%0A
         
 if data%5B
@@ -1707,48 +1707,82 @@
     
-if data%5B1%5D.find('%22') != -1:%0A     
+# %D1%8D%D0%BA%D1%80%D0%B0%D0%BD%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5 %D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB%D0%B0 '%22' %D0%B2 %D1%8F%D1%87%D0%B5%D0%B9%D0%BA%D0%B8 %D0%B8 %D1%81%D0%B0%D0%BC%D0%BE%D0%B9 %D1%8F%D1%87%D0%B5%D0%B9%D0%BA%D0%B8 %D1%8D%D1%82%D0%B8%D0%BC %D1%81%D0%B8%D0%BC%D0%B2%D0%BE%D0%BB%D0%BE%D0%BC%0A
        
+ 
 csv_
@@ -1838,74 +1838,27 @@
 ' + 
-%22;%22%0A            csv_file.write(csv_data)%0A        else:%0A   
+delimiter%0A%0A
         
  csv
@@ -1849,25 +1849,24 @@
 er%0A%0A        
- 
 csv_file.wri
@@ -1872,26 +1872,16 @@
 ite(
+csv_
 data
-%5B1%5D%5B:-2%5D + %22;%22
 )%0A  

Изменил алгоритм экранирования. теперь экранируется любая ячейка. Разделитель можно задавать переменной delimiter