readline() & seek() ???
cwitts at gmail.com
Fri Jun 6 08:36:33 CEST 2008
On Jun 6, 5:13 am, Kam-Hung Soh <kamhung.... at gmail.com> wrote:
> Tim Roberts wrote:
> > DataSmash <r... at new.rr.com> wrote:
> >> I have a text file that contains thousands of lines and each line is
> >> 256 characters long.
> >> This is my task:
> >> For each line in the file, move to the 25th character, if the
> >> character is a "T",
> >> move to the 35th character of the line and read 5 characters from
> >> there.
> >> Capture these 5 characters and write them to a new text file, each 5
> >> characters separated by a comma.
> >> I appreciate your help!
> > Did you even TRY this? Your task reads like pseudocode that translates
> > virtually line-for-line to Python code.
> > fout = open('outputfile.txt','w')
> > for line in open('inputfile.txt'):
> > if line == 'T':
> > fout.write( line[34:39] + ',' )
> Should the last line be ...
> Kam-Hung Soh <a href="http://kamhungsoh.com/blog">Software Salariman</a>
each 5 characters need to be delimited by a comma, your statement
would have a comma between each of the 5 characters.
More information about the Python-list