First, read each line from the file and then use the title() function to capitalize each word in the line.
string.title()Example program to capitalize the first letter of every word in a file in Python
Simple example code takes the content of the file as input and Prints it after altering it.
fname = "file.txt"
with open(fname, 'r') as f:
for line in f:
l = line.title()
print(l)
Output:

Inside File.txt

Do comment if you have any comments or suggestions on this Python capitalize program.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.