jfz-2023-s473579/TaskD04/run.py

41 lines
1.4 KiB
Python
Raw Normal View History

2023-11-27 22:38:20 +01:00
import re
import sys
def write_answer(row, ouput_file,character):
with open(ouput_file, "a", encoding="utf-8") as file:
file.write(row+character)
def main_function(pattern, input_file, output_file):
with open(output_file, "w", encoding="utf-8") as output_file1:
with open(input_file, "r", encoding="utf-8") as file:
for row in file:
checkWord = ''
allLine = ''
for letter in row:
if checkWord != '':
if re.search(pattern, letter):
checkWord += letter
else:
allLine += checkWord
allLine += ' '
write_answer(checkWord, output_file, ' ')
checkWord = ''
else:
if re.search(pattern, letter):
checkWord += letter
if letter == '\n':
if allLine != '':
write_answer('', output_file, '\n')
allLine = ''
# pattern = re.compile(r'(?:^|\s)pies(?:\s|$)', re.IGNORECASE)
pattern = r'\d+'
# output_file ='simple.out'
# input_file = 'simple.in'
input_file = sys.argv[1]
output_file = sys.argv[2]
main_function(pattern, input_file, output_file)