<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">Hi all,</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">I know below query may sound silly, but can somebody suggest any better way of doing this:<br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">It would be helpful.</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">I need to read a file line by line and print each line starting from the last word first:</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">&nbsp;</div><div><div><font class="Apple-style-span"
 face="arial, helvetica, sans-serif">C:\Python26&gt;type file_reversing_program.txt<br></font></div><div><font class="Apple-style-span"><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">import sys</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">import string</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">f_obj=open(sys.argv[1],"r")</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">for eachline in f_obj:</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">&nbsp; &nbsp;<span class="Apple-style-span" style="background-color: rgb(255, 255, 128);"> eachline=eachline[ :-1]</span><span class="Apple-tab-span"
 style="white-space:pre">                                </span><font class="Apple-style-span"># </font></font><font class="Apple-style-span" face="arial, helvetica, sans-serif">to eliminate the trailing "\n"</font><font class="Apple-style-span" face="arial, helvetica, sans-serif" size="2">&nbsp;</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">&nbsp; &nbsp; list_words=eachline.split(" ")</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">&nbsp; &nbsp;<span class="Apple-style-span" style="background-color: rgb(255, 255, 128);"> list_words[0]=list_words[0]+"\n"</span><span class="Apple-tab-span" style="white-space:pre">                </span># to add "\n" so that after line 1 is printed, line 2 should start on a new line&nbsp;</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">&nbsp; &nbsp; list_words.reverse()</font></div><div><font class="Apple-style-span" face="arial, helvetica,
 sans-serif">&nbsp; &nbsp; for every_word in list_words:</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;print every_word,<span class="Apple-tab-span" style="white-space:pre">                                        </span># &nbsp;'comma' helps in printing words on same line,hence for last word we append "\n"&nbsp;</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">f_obj.close()</font></div><div><br></div></font></div><div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">C:\Python26&gt;type input_file.txt<br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">"Hi ther, how are you?"</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">I are doing fine, thank you.</font></div><div><font class="Apple-style-span"
 face="arial, helvetica, sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">C:\Python26&gt;file_reversing_program.py input_file.txt<br></font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">you?<span class="Apple-style-span" style="background-color: rgb(128, 255, 255);">"</span> are how ther,<span class="Apple-style-span" style="background-color: rgb(128, 255, 255);"> "</span>Hi</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">you. thank fine, doing are I</font></div></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">Is there a better way of doing the above program, mainly the text highlighted in yellow,</font></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times,
 serif">Also if that is settled can there be a logic for getting the ouput more properly formatted&nbsp;</font><span class="Apple-style-span" style="font-family: 'times new roman', 'new york', times, serif; ">(for text in blue)&nbsp;</span><span class="Apple-style-span" style="font-family: 'times new roman', 'new york', times, serif; ">,&nbsp;</span></div><div><font class="Apple-style-span" face="'times new roman', 'new york', times, serif">say giving an output like &nbsp;:</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">"you? are how ther, Hi"</font></div><div><font class="Apple-style-span" face="arial, helvetica, sans-serif">you. thank fine, doing are I</font><font class="Apple-style-span" face="'times new roman', 'new york', times, serif"><br></font></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><br></div><div style="font-family: 'times new roman', 'new york', times,
 serif; font-size: 12pt; "><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">Thanks,</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; ">Neha</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt; "><br></div></div></div></body></html>