Hmm...thanks Kent. Could use such information myself. I did feel that my code was bloated or could be tweaked somehow.
Ha...there i double posted again :( Am having trouble paying attention today. On Wed, Feb 4, 2009 at 5:42 PM, Kent Johnson <ken...@tds.net> wrote: > On Wed, Feb 4, 2009 at 10:18 AM, OkaMthembo <zebr...@gmail.com> wrote: > > The following is adapted from my humble text processing script that i use > at > > work for a recurring task of mine. Any excuse not to use Java all day :) > > > > There was an error with my other posts. Pardon the triple posting - won't > > happen again soon. > > > > > > > > file_1 = open('step2', 'r+') > > lines = file_1.readlines() > > sentences = [] > > for line in lines: > > if line: > > I don't think line will ever be empty, so this test is not needed. > > > sentences.insert(len(sentences), line + '-d') > > sentences.append(line + '-d') is simpler. Note this appends after the > newline so it is not really what the OP wants. > > > file_1.close() > > file_2 = open('pyout', 'w+') > > if len(sentences) > 0: > > This test is not needed, if sentences is empty the for statement won't > do anything. > > > for sentence in sentences: > > file_2.write(sentence) > > The loop could be replaced with > file_2.writelines(sentences) > > Kent > -- Lloyd Dube
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor