Category Archives: Python File Programs – Python File Handling

Python File Phonebook Program

Topic: Python file Phonebook Python file Phonebook Program: Write a Python Program using text files to create and maintain a Phone Book. The Phone Book will display the following Menu and will support the corresponding functionality: *** Phone Book Menu *** Enter 1,2,3 or 4: Enter 1 To Display Your Contacts Records Enter 2 To… Read More »

 469 total views,  6 views today

Python File Copy Program using shutil.filecopy

Topic: Python File Copy Program using shutil.filecopy You can easily copy a source file to a destination file. For this purpose, perform the following steps: import shutil module, because the shutil module provides the copyfile() function to copy a source file into a destination file. input source file name input destination file name call shutil.copyfile(sourcefile,destinationfile)… Read More »

 84 total views,  1 views today

Find Occurrences of Each Word in Text File Python Program

Topic: Write a Python Program to Find Occurrences of Each Word in Text File Python Program Source Code : Python Program using Text File # Python program to count # number of occurences / frequencies of words in a text # Input filename, open it in # read mode. display its cntents # count and… Read More »

 694 total views,  6 views today

Count Words in Each Line of Text File Python

Topic: Count Words in Each Line of Text File Python Program   # Python program to count # number of words in each line of a text file separately # Input filename, open it in # read mode. display its cntents # count and display number of words # www.EasyCodeBook.com file_name = input(“Enter file name:”)… Read More »

 537 total views,  8 views today

Python Count Words in Text File

Topic: Count Words in Text File Python Program # Python program to count # number of words in a text file # Input filename, open it in # read mode. display its cntents # count and display number of words # www.EasyCodeBook.com file_name = input(“Enter file name:”) file1 = open(file_name, “r”) word_count = 0 print(“Contents… Read More »

 129 total views,  1 views today

Count Lines in Text File Python Program

Topic: Count Lines in Text File Python Program # Python program to count # number of lines in a file # Input filename, open it in # read mode. display its cntents # count and display number of lines # www.EasyCodeBook.com file_name = input(“Enter file name:”) file1 = open(file_name, “r”) line_count = 0 print(“Contents of… Read More »

 188 total views,  4 views today

Python Text File Program To Count Vowels

Task: Write a Python Text File Program To Count Vowels. This Python Programming tutorial will explain how to open a text file in read mode. This Python script will count the how many vowels are present in this text file. For this program we will assume that: The file has the name mytext.txt and it… Read More »

 1,469 total views,  22 views today

Python File Program Count Characters in Text File

Task: Write a Python File Program To Count Characters in Text File. This Python Programming tutorial will explain a simple logic to show number of characters in a text file. The Python programming language provides open() function. We will use open() function to open an existing file in read mode. As we know that the… Read More »

 183 total views,  2 views today

Python Exception Handling FileNotFoundError

Task: Python Exception Handling FileNotFoundError –  If the user enters a wrong name or path for the file, this program will handle it gracefully by showing a simple and easy to understand error message. How To Handle FileNotFound Exception in Python? We will use try-except block to handle FileNotFound exception. Note that the try-block will… Read More »

 332 total views,  6 views today

Python Text File Read and Show File Contents

  Task: Python Text File Read and Show File. This Python programming tutorial will use open(), read() and print() functions to read and display the whole contents of a text file on the drive D. First of all, we assume that the text file mytext.txt already exist on the D drive. Otherwise you can use… Read More »

 403 total views,  6 views today