begin = open(beginfile, 'rt') finish = open(file, 'wt') count = 0 while True: line = begin.readline() if not line: break if 'name' in line: line = line.replace('name', 'Surname') count += 1 finish.write(line) finish.close() begin.close() return count add = additional poem = "What's Montague? It is nor hand, nor foot, \ \nNor arm, nor face, nor any other part \ \nBelonging to a man. O, be some other name.\ \nWhat's in a name? That which we call a rose\ \nBy any other name would smell as sweet" input_file = 'txt\lab4var3in.txt' output_file = 'txt\lab4var3out.txt' additional.writer(poem, input_file) found = name_(input_file, output_file) additional.user_input_num(input_file, output_file) print(found)
finish = open(file, 'wt') count = 0 while True: line = begin.readline() line = line.strip('\n') if not line: break if line.endswith("0"): finish.write(line + '\n') count += 1 finish.close() begin.close() return count shopping_list = "Бананы 12.23\ \nАнанасы 3.40 \ \nКокосы 124.23\ \nЯблоки 233.40\ \nЛимоны 789.23\ \nГранат 55.71\ \nВиноград 5.20\ \nСливы 233.40" input_file = 'txt\lab4var7in.txt' output_file = 'txt\lab4var7out.txt' additional.writer(shopping_list, input_file) empty = zero(input_file, output_file) additional.user_input_num(input_file, output_file)
import additional import re def change_str(beginfile: str, file: str): begin = open(beginfile, 'rt') finish = open(file, 'wt') while True: c_line = begin.readline() if not c_line: break line1 = re.search("(@\w+(\.\w+)+)", c_line) finish.write(str(line1[0]).lstrip('@')) finish.close() begin.close() line = "From [email protected] Sat Jan 5 09:14:16 2018 " input_file = 'txt\lab4var5in.txt' output_file = 'txt\lab4var5out.txt' additional.writer(line, input_file) change_str(input_file, output_file) additional.user_input_num(input_file, output_file)
def pass_s_words(beginfile: str, file: str): begin = open(beginfile, 'rt') finish = open(file, 'wt') new_line = "" while True: line = begin.readline() if not line: break password = re.search(":[1-9]+", line) myset = line.split(' ') for p in myset: if ":" in p: continue else: new_line += p.title() + " " finish.write(new_line) finish.close() begin.close() return str(password[0]).lstrip(':') string = "d:/ФайлыPython/files/file1.txt Log:Admin1 Password:12345 send message saturday january 2018 Stephen" input_file = 'txt\lab4var8in.txt' output_file = 'txt\lab4var8out.txt' additional.writer(string, input_file) pas = pass_s_words(input_file, output_file) additional.user_input_num(input_file, output_file) print(pas)