Python Practice › File Handling Programs › Program 13
Copy a file in uppercase
Write a Python program to copy a file’s contents to another file in uppercase.
Output
HELLO WORLD PYTHON FILES
Approach
- Process line by line so large files work too.
Solution
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.