<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3">Dear Group,</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3">I am working on a code like the following:</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3">from decimal import*</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3">#SAMPLE TEST PROGRAM FOR FILE</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3">def sample_file_test(n):</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>#FILE FOR STORING PROBABILITY VALUES</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>open_file=open("/python26/Newfile1.txt","r+")</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>#OPENING OF ENGLISH CORPUS</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes">   </span>open_corp_eng=open("/python26/TOTALENGLISHCORPUS1.txt","r")</font></font></p>

<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>#READING THE ENGLISH CORPUS</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>corp_read=open_corp_eng.read()</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>#CONVERTING THE CORPUS FILE IN WORDS</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>corp_word=corp_read.split()</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>#EXTRACTING WORDS FROM CORPUS FILE OF WORDS</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>for word in corp_word:</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>#COUNTING THE WORD</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>count1=corp_word.count(word)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>#COUNTING TOTAL NUMBER OF WORDS</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>count2=len(corp_word)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>#COUNTING PROBABILITY OF WORD</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>count1_dec=Decimal(count1)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>count2_dec=Decimal(count2)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>getcontext().prec = 6</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>prob_count=count1_dec/count2_dec</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>print prob_count</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>string_of_prob_count=str(prob_count)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>file_input_val=open_file.write(string_of_prob_count)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">        </span>open_file.close()</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt"><font face="Times New Roman" size="3">The problems I am getting:</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.5in; mso-list: l0 level1 lfo1; tab-stops: list .75in"><font face="Times New Roman"><span style="mso-list: Ignore"><font size="3">(i)</font><span style="FONT: 7pt 'Times New Roman'">                  </span></span><font size="3">The probability values are not being stored properly in file.</font></font></p>

<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.5in; mso-list: l0 level1 lfo1; tab-stops: list .75in"><font face="Times New Roman"><span style="mso-list: Ignore"><font size="3">(ii)</font><span style="FONT: 7pt 'Times New Roman'">                </span></span><font size="3">“Newfile1.txt” is storing not the series of values but an arbitrary value from series 0.00000143096</font></font></p>

<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.75in; TEXT-INDENT: -0.5in; mso-list: l0 level1 lfo1; tab-stops: list .75in"><font face="Times New Roman"><span style="mso-list: Ignore"><font size="3">(iii)</font><span style="FONT: 7pt 'Times New Roman'">               </span></span><font size="3">As I was testing it again it gave me another error </font></font></p>

<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3">Traceback (most recent call last):</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">  </span>File "<pyshell#2>", line 1, in <module></font></font></p>

<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>sample_file_test(1)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">  </span>File "C:\Python26\testprogramforfiles1.py", line 25, in sample_file_test</font></font></p>

<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font size="3"><font face="Times New Roman"><span style="mso-spacerun: yes">    </span>file_input_val=open_file.write(string_of_prob_count)</font></font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3">ValueError: I/O operation on closed file</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3">If you can kindly let me know what is the wrong I am doing here.</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3">As I took out the code pasted it in MS-Word before posting, there may be slight indentation problem.</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3"> </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3">Best Regards,</font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3">Subhabrata. </font></p>
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt 0.25in"><font face="Times New Roman" size="3"> </font></p><br><br>
<div class="gmail_quote">On Sat, May 2, 2009 at 2:16 PM, Pascal Chambon <span dir="ltr"><<a href="mailto:chambon.pascal@wanadoo.fr">chambon.pascal@wanadoo.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><a href="mailto:subhakolkata1234@gmail.com" target="_blank">subhakolkata1234@gmail.com</a> a écrit :<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div>
<div></div>
<div class="h5">Dear Group,<br><br>I am using Python2.6 and has created a file where I like to write some<br>statistical values I am generating. The statistical values are<br>generating in a nice way, but as I am going to write it, it is not<br>
taking it, the file is opening or closing properly but the values are<br>not getting stored. It is picking up arbitrary values from the<br>generated set of values and storing it. Is there any solution for it?<br><br>Best Regards,<br>
SBanerjee.<br></div></div>--<br><a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br><br><br> <br></blockquote>Hello<br><br>Could you post excerpt of your file-handling code ?<br>
It might be a buffering problem (although when the file closes, I think buffers get flushed), else it's really weird...<br><br>Regards,<br><font color="#888888">pascal<br><br></font></blockquote></div><br>