kaushik kaushik - 9 months ago 46
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?

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