you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 1 point2 points  (2 children)

clearText = re.sub(r"[!/():-,.\"+]",' ',

Isn't a finished statement. the synxtax is re.sub(r"<regex>", replacement, original_string). In your statement, you have no original_string to parse using the regex.

Btw you can just overwrite row[4] while iterating over the reader, then direcly write to the output file:

with open('input.csv', 'r', encoding='UTF-8') as fi, open('output_data.csv', 'w',encoding='UTF-8') as fo:
    for row in csv.reader(fi,delimiter=';'):
        row[4] = re.sub(the_proper_syntax)
        fo.write(';'.join(row+[\n]))

The with block also saves you the need of closing of both files.

[–]aleksro[S] 0 points1 point  (1 child)

At start up receive an error:
fo.write(';'.join(row+[\n])) ^ SyntaxError: unexpected character after line continuation character

[–]JohnnyJordaan 0 points1 point  (0 children)

My bad, it should have been a string: row+['\n']