The task is to read the file and print the words char-by-char.
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()
- 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.