Generate a file that stores matches that match the Regular Expression of a reading file

0

I want to store the data that made match with the regular expression, I want this data to be stored and generate a new file with the name of the file that was read and all these address to a folder

import re

pattern1 = re.compile(r"(\w+:\w+\s?= status)|(\w{7,}\s?= status)")

with open("C:\Curso Python\YTS\s.YT3792B","r") as f:            
    leer = f.read()
    matches = pattern1.finditer(leer)


for match in matches:
    print(match)
    
asked by David 12.10.2018 в 03:28
source

1 answer

0

You could do something like:

MyFile=open("nombredelarchivo.txt", 'w')
MyFile=write(X)

In X you should write whatever you want to enter in the file. In this case I guess what you want to write is what is in 'matches'. Remember that in the end you will have to close the file ( MyFile.close() ).

    
answered by 14.10.2018 / 13:35
source