0

I am trying to read a text file and remove anything in between quotes ("") and also any kind of commas and semi-colons.

I also want to insert a line before the string of characters 'qwe'.

I have no experience with python and I have been tasked to this in python.

Rahul
  • 903
  • 1
  • 10
  • 27

2 Answers2

1
import re
with open('code.txt', 'r') as infile, open('noquotes.txt', 'w') as outfile:
    for line in infile:
        x=''
        line=re.sub('".+?"', '', line)
        for i in range(len(line)):
            if str(line[i])!=',':
                x+=str(line[i])
            if str(line[i])== ',':
                pass
    outfile.write(x)
    outfile.close(x)

I got it :D

Rahul
  • 903
  • 1
  • 10
  • 27
0
f = open('filename.txt', 'r')
for line in f:
    x=''
    for i in range(len(line)):
        if str(line[i]) != ',':
            x += str(line[i])
        if str(line[i]) == ',':
            pass
print (x)

Here's some example code to read and remove comma's from a text file, you can start from this and try adding all the other stuff you want to do. Just have this code saved in the same place as the text file and type the text file's name where it says filename.

Calum Beck
  • 25
  • 1
  • 1
  • 7