Scanning a file character by character

Bard Aase elzapp at gmail.com
Thu Feb 5 08:03:06 CET 2009


On 5 Feb, 07:48, Spacebar265 <spacebar... at gmail.com> wrote:
> Hi. Does anyone know how to scan a file character by character and
> have each character so I can put it into a variable. I am attempting
> to make a chatbot and need this to read the saved input to look for
> spelling mistakes and further analysis of user input.
> Thanks
> Spacebar265

You can read one byte at the time using the read() method on the file-
object.
http://docs.python.org/library/stdtypes.html#file.read

e.g.:
f=open("myfile.txt")
byte=f.read(1)



More information about the Python-list mailing list