Mega Code Archive

 
Categories / Python / File
 

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()