File handling problem.
subhakolkata1234 at gmail.com
Sun May 3 12:51:13 EDT 2009
I am working on a code like the following:
from decimal import*
#SAMPLE TEST PROGRAM FOR FILE
#FILE FOR STORING PROBABILITY VALUES
#OPENING OF ENGLISH CORPUS
#READING THE ENGLISH CORPUS
#CONVERTING THE CORPUS FILE IN WORDS
#EXTRACTING WORDS FROM CORPUS FILE OF WORDS
for word in corp_word:
#COUNTING THE WORD
#COUNTING TOTAL NUMBER OF WORDS
#COUNTING PROBABILITY OF WORD
getcontext().prec = 6
The problems I am getting:
(i) The probability values are not being stored properly in
(ii) “Newfile1.txt” is storing not the series of values but
an arbitrary value from series 0.00000143096
(iii) As I was testing it again it gave me another error
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
File "C:\Python26\testprogramforfiles1.py", line 25, in sample_file_test
ValueError: I/O operation on closed file
If you can kindly let me know what is the wrong I am doing here.
As I took out the code pasted it in MS-Word before posting, there may be
slight indentation problem.
On Sat, May 2, 2009 at 2:16 PM, Pascal Chambon <chambon.pascal at wanadoo.fr>wrote:
> subhakolkata1234 at gmail.com a écrit :
>> Dear Group,
>> I am using Python2.6 and has created a file where I like to write some
>> statistical values I am generating. The statistical values are
>> generating in a nice way, but as I am going to write it, it is not
>> taking it, the file is opening or closing properly but the values are
>> not getting stored. It is picking up arbitrary values from the
>> generated set of values and storing it. Is there any solution for it?
>> Best Regards,
> Could you post excerpt of your file-handling code ?
> It might be a buffering problem (although when the file closes, I think
> buffers get flushed), else it's really weird...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list