[Tutor] how to read from a txt file

jrlen balane nbbalane at gmail.com
Sun Feb 13 17:49:36 CET 2005

guys, how would i do this: 
i want to read from a text file
the text file should contain should contain data (say, decimal value
from 1-1200). there should be no other type of entry but decimal
it should contain 96 data all in all, with each data separated by a
comma or each data is numbered from 1-96 (or better yet, any
suggestions on this???)
now, the program should read each data every 5 minutes for eight hours
the data will be sent to the serial port and will be executed by an
external hardware. the serial part is ok, and the problem now is how
to read from a text file.
any help, pls.

what i know (chapter 7 of the tutorial):
1) first, to open a txt file, i can use open() say:
                f = open(*.txt, r)
a user can use the notepad to create the text file so i'll just open
it for reading. my problem now would be on reading the contents of the
2) f.read(size), since my data ranges from 0-1200, size = 2 for each read.
3) should i do this:
       for data in range (1, 96,1):
            time.sleep(300) # 5 minutes
4) since f.read() returns string, how would i convert this back to
decimal value, since i would need the decimal value for the serial

please help, will try to formulate some questions later to make the
problem clearer. thanks in advance...

More information about the Tutor mailing list