Table of Contents
Introduction
The task is to read the file and print the words char-by-char.
Program
ip_file = open("demo.txt", "r") while 1: read_char = ip_file.read(1) if not read_char: break #print char print(read_char) ip_file.close()
Output
Explanation
Approach:
- Open file using open() function.
- Read character using read() function. The argument to read() function is the number of characters you want to read at a time.
- Print the character.
0 Comments