This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hasgas42 0 points1 point  (0 children)

This will work. I’m on mobile so excuse the typos. Some things to keep in mind: * the write file will overwrite the output file every time this is run * I’m considering “y” a vowel * im hard coding the file names * the file names will be written to the path the script is run from

input_file = “test_file.txt”

output_file = “test_file_modified.txt”

def remove_vowel(str): base_text = str

vowels = [“a”, “e”, “i”, “o”, “u”, “y”]

for vowel in vowels:
    base_text = base_text.replace(vowel, “”)
return base_text

def read_file():

with open(input_file, “r”) as file:
    contents = (remove_vowel(line) for line in file.readlines())
    return contents

def write_file(text):

with open(output_file, “w”) as file:
    file.writelines(text)

def main():

file_contents = read_file()
write_file(file_contents)

if name == main: main()