Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # this program opens a sample text file
- # and capitalizes every word in that file and
- # assigns it to a new file
- # specify the file name to open
- filename = "sample2.txt"
- # Open the file in read-only mode
- file = open(filename, "r")
- # specify the filename for the new data
- filename_new = "sample2CAP.txt"
- # Open the file in write-only mode
- file_new = open(filename_new, "w")
- # read entire contents of the input file to capitialize
- str = file.read()
- # capitalize every word in the input file
- cap_words = str.title()
- # write the data to a new file with every word capitalized
- file_new.write(cap_words)
- # we are now done so it is now time to close both of the files
- file.close()
- file_new.close()
Advertisement
Add Comment
Please, Sign In to add comment