Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

KeyboardInterrupt close failed in file object destructor: sys.excepthook is missing lost sys.stderr

91 views
Skip to first unread message

Jai

unread,
Nov 19, 2013, 10:35:22 AM11/19/13
to
Code
#################################

#!/usr/bin/env python


import sys, re




def find_position(line):
pun = ""
if re.search(r"[.?!]+", line):
pun = re.search(r"[.?!]+", line).group()
pos = line.find(pun)
pos = pos+len(pun)-1
return pos




def sentence_splitter(filename):

f = open(filename, "r")

for line in f:
line = line.strip()
print line + "\n"
while line:
pos = find_position(line)
line2 = line[ : pos+1].split(" ")
length = len(line2)
last_word = line2[length -1]

try:
if re.search(r"[A-Z]+.*", last_word) or line[pos+1] != " " or line[pos+2].islower() :
print line[:pos+1],
line = line[pos+1:]

else:
print line[ : pos+1]
line = line[pos+1 :]


except :
print " error here!!"

f.close()
return " bye bye"





if __name__=="__main__":
print sentence_splitter(sys.argv[1])


##########################3

exicution

python sentence_splitter6.py README | more


###############

README

Mr. Smith bought example.cheapsite.com for 1.5 million dollars, i.e. he paid a lot for it. Did he mind? Adam Jones Jr. thinks he didn't. In any case, this isn't true... Well, with a probability of .9 it isn't. The result should be:
~
############################


output

Mr. Smith bought example.cheapsite.com for 1.5 million dollars, i.e. he paid a lot for it. Did he mind? Adam Jones Jr. thinks he didn't.
In any case, this isn't true... Well, with a probability of .9 it isn't. The result should be:

Mr. Smith bought example. cheapsite. com for 1. 5 million dollars, i. e. he paid a lot for it.
Did he mind?
Adam Jones Jr. thinks he didn't.
In any case, this isn't true...
Well, with a probability of . 9 it isn't.

##########################################################3

error

KeyboardInterrupt
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr

##########################################


please help what is this i have try lot but unable to remove it





Mark Lawrence

unread,
Nov 19, 2013, 11:08:20 AM11/19/13
to pytho...@python.org
Please help us to help you by stating your OS and Python versions.
Remove that dreadful bare exception which is masking everything in the
try block that could possibly go wrong, rerun your code and see what
happens. If you get a traceback display all of it for us to see via cut
and paste, don't paraphrase.

Finally the obligatory request for google users, would you please read
and action this https://wiki.python.org/moin/GoogleGroupsPython to
prevent us seeing potential double line spacing, thanks.

--
Python is the second best programming language in the world.
But the best has yet to be invented. Christian Tismer

Mark Lawrence

Neil Cerutti

unread,
Nov 19, 2013, 11:42:35 AM11/19/13
to pytho...@python.org
MOn Tue, Nov 19, 2013 at 10:35 AM, Jai
> please help what is this i have try lot but unable to remove it

Your code is getting into an infinite loop.

One problem is, I suspect:

> def find_position(line):
>     pun = ""
>     if re.search(r"[.?!]+", line):
>         pun = re.search(r"[.?!]+", line).group()
>     pos = line.find(pun)
>     pos = pos+len(pun)-1
>     return pos

When your search fails, this function will return 0. Fix that.

In general your problem isn't well defined enough for me to make
sense of your algorithm. Can you show sample input and output?
Can you describe the algorithm in plain English?

-- 
Neil Cerutti
0 new messages