kaushik kaushik - 3 months ago 7
Python Question

How to read a single character at a time from a file in Python?

Can anyone tell me how can I do this?

Answer
with open(filename) as f:
  while True:
    c = f.read(1)
    if not c:
      print "End of file"
      break
    print "Read a character:", c