Copy a file in uppercase

EasyFile Handling Programs · 13 of 38

Write a Python program to copy a file’s contents to another file in uppercase.

Advertisement
Output
HELLO WORLD
PYTHON FILES

Approach

  1. Process line by line so large files work too.

Solution

Python
with open("in.txt", "w") as f:    f.write("Hello World\nPython Files\n") with open("in.txt") as src, open("upper.txt", "w") as dst:    for line in src:        dst.write(line.upper())print(open("upper.txt").read())
Output
HELLO WORLD
PYTHON FILES

Learn the concept

New to this topic? Read the lesson, then come back.

More file handling programs

← All 38 File Handling Programs

Leave a Comment