Python 3 Script to Capitalize First Letter of Every Word inside Text File Full Tutorial For Beginners

Python 3 Script to Capitalize First Letter of Every Word inside Text File Full Tutorial For Beginners

 

Welcome folks today in this post we will be capitalize first letter of every word in python. All the full source code of application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

app.py

 

# Python program to read a file and capitalize 
# the first letter of every word in the file. 

# A file named "gfg", will be opened with the 
# reading mode. 
file_gfg = open('file.txt', 'r') 
output=""
# This will traverse through every line one by one 
# in the file 
for line in file_gfg: 
    
    # This will convert the content 
    # of that line with capitalized 
    # first letter of every word 
    output+=line.title() 
    
    # This will print the output 
    print(output)

f = open("output.txt","w")

f.write(output)

 

See also  Python 3 Github API Web Scraper or Crawler Script to Scrape User Profile and Repositories Details Using requests and json Modules Full Project For Beginners

 

Now if you execute the above python script by typing the below command as shown below

 

python app.py

 

So it will take the following input text file and then process it and then create the output text file as shown below

 

 

Leave a Reply