Turn the whole file uppercase

Open both files using with, which will close the files for you. Read the original file’s contents, convert them to upper case, and write them to the new file.

with open('tobe.txt', 'r') as original_file:
    with open('tobeUPPER.txt', 'w') as new_file:
        new_file.write(original_file.read().upper())

Leave a Comment