{"id":9744,"date":"2021-09-30T14:00:17","date_gmt":"2021-09-30T08:30:17","guid":{"rendered":"https:\/\/python-programs.com\/?p=9744"},"modified":"2021-11-22T18:34:36","modified_gmt":"2021-11-22T13:04:36","slug":"python-program-to-read-a-file-and-capitalize-the-first-letter-of-every-word-in-the-file","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-read-a-file-and-capitalize-the-first-letter-of-every-word-in-the-file\/","title":{"rendered":"Python Program to Read a File and Capitalize the First Letter of Every Word in the File"},"content":{"rendered":"
Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example<\/a> guide and practice well.<\/p>\n Files in Python:<\/strong><\/p>\n A file is a piece of information or data that is kept in computer storage devices. You are already familiar with several types of files, such as music files, video files, and text files. Python makes it simple to manipulate these files. In general, files are classified into two types: text files and binary files. Text files are plain text, whereas binary files include binary data that can only be read by a computer.<\/p>\n Python file handling (also known as File I\/O) is an important topic for programmers and automation testers. It is necessary to work with files in order to either write to or read data from them.<\/p>\n Furthermore, if you are not already aware, I\/O operations are the most expensive procedures through which a program might fail. As a result, you should take caution while implementing file handling for reporting or any other reason. Optimizing a single file activity can contribute to the development of a high-performance application or a solid solution for automated software testing.<\/p>\n Given\u00a0 a file, thee= task is to read the given file and capitalize the first letter of every word in the given file<\/p>\n Below is the full process Read a File and Capitalize the First Letter of Every Word in the File.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Explanation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Before Modifying:<\/strong><\/p>\n After Modifying:<\/strong><\/p>\n Google Colab Images:<\/strong><\/p>\n Files and Code:<\/strong><\/p>\n <\/p>\n Code:<\/strong><\/p>\n ‘<\/p>\n Output Image:<\/strong><\/p>\n <\/p>\n Sample file:<\/strong><\/p>\n <\/p>\n Related Programs<\/strong>:<\/p>\n Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example guide and practice well. Files in Python: A file is a piece of information or data that is kept in computer storage devices. You are already familiar with several types of files, such as music files, video …<\/p>\nProgram to Read a File and Capitalize the First Letter of Every Word in the File<\/h2>\n
\n
# Enter the file name of the first file using the input() function and store it in a variable.\r\nfilename = input(\"Enter the first file name = \")\r\n# In read mode, open the first file with the entered file name.\r\nwith open(filename, 'r') as givenfile:\r\n # Using for loop, go over the lines in the first file.\r\n for fileline in givenfile:\r\n # To capitalize each word in the line, use the title() function.\r\n line = fileline.title()\r\n # Print the file's modified lines.\r\n print(line)\r\n<\/pre>\n
\n
Python is a high-level, object-oriented, interpretable, dynamic semantic programming language.\r\nIts high-level data structures, along with dynamic typing and dynamic connections are particularly \r\ninteresting both for the development of rapid application and for the usage as a script or glue language \r\nin connecting existing components. The basic, easy syntax of Python underlines readability and hence saves \r\nsoftware maintenance costs.\r\nPython allows modules and packages, which promote the modularity of the programme and the reuse of code.\r\nThe Python interpreter and the vast standard library can be freely supplied, either as a source or as a binary,\r\nfor all major platforms without payment.The improved productivity of programmers is often a result of the love of Python.\r\nThe edit-test-debug cycle is extraordinarily rapid, given there is no compilation stage. It is easy to debug \r\nPython programmes: a bug or poor input never causes segmentation errors. Rather, it does raise an exception when the\r\ninterpreter discovers an error. The tracer prints a stack track if the programme does not catch the exception.\r\nA source level debugger allows you to check local and global variables, evaluate arbits, set breakpoints, \r\nline by line code, and so on. A source level debugger is available. The debugger is written in Python, \r\nshowing the introspective power of Python. On the other hand, the most easy way of debugging a programme often is to\r\nadd several print statements to the source: this basic approach has a fast editing-test-debug cycle.<\/pre>\n
Enter the first file name = samplefile1.txt\r\nPython Is A High-Level, Object-Oriented, Interpretable, Dynamic Semantic Programming Language.\r\nIts High-Level Data Structures, Along With Dynamic Typing And Dynamic Connections Are Particularly\r\nInteresting Both For The Development Of Rapid Application And For The Usage As A Script Or Glue Language\r\nIn Connecting Existing Components. The Basic, Easy Syntax Of Python Underlines Readability And Hence Saves\r\nSoftware Maintenance Costs.\r\nPython Allows Modules And Packages, Which Promote The Modularity Of The Programme And The Reuse Of Code.\r\nThe Python Interpreter And The Vast Standard Library Can Be Freely Supplied, Either As A Source Or As A Binary,\r\nFor All Major Platforms Without Payment.The Improved Productivity Of Programmers Is Often A Result Of The Love Of Python.\r\nThe Edit-Test-Debug Cycle Is Extraordinarily Rapid, Given There Is No Compilation Stage. It Is Easy To Debug\r\nPython Programmes: A Bug Or Poor Input Never Causes Segmentation Errors. Rather, It Does Raise An Exception When The\r\nInterpreter Discovers An Error. The Tracer Prints A Stack Track If The Programme Does Not Catch The Exception.\r\nA Source Level Debugger Allows You To Check Local And Global Variables, Evaluate Arbits, Set Breakpoints,\r\nLine By Line Code, And So On. A Source Level Debugger Is Available. The Debugger Is Written In Python,\r\nShowing The Introspective Power Of Python. On The Other Hand, The Most Easy Way Of Debugging A Programme Often \r\nIs To Add Several Print Statements To The Source: This Basic Approach Has A Fast Editing-Test-Debug Cycle.<\/pre>\n
\n