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

Mark Lawrence breamoreboy at yahoo.co.uk
Tue Nov 19 17:08:20 CET 2013


On 19/11/2013 15:35, Jai wrote:
> 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
>

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




More information about the Python-list mailing list