Open a file and read char by char : File Read « File « Python






Open a file and read char by char

file = open('test.txt', 'r')
print file.read()

while 1:
    char = file.read(1)          # read by character
    if not char: break
    print char,

file.close()
           
       








Related examples in the same category

1.File read(n)
2.File read() Demo
3.File readline()File readline()
4.File readlines
5.Looping Over Characters with read
6.Reading Everything: read the whole file in one go
7.Iterating Over Lines with readlines
8.Loop through a file