kaushik kaushik - 1 year ago 93
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 Source
with open(filename) as f:
  while True:
    c = f.read(1)
    if not c:
      print "End of file"
    print "Read a character:", c
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download