best way to extract sentence from txt file

Michiel Overtoom motoom at xs4all.nl
Tue May 17 14:40:40 EDT 2011


On May 17, 2011, at 20:22, Robert Pazur wrote:

> my question is maybe quite simple:
> What is the best (and shortest) way to extract sentence from .txt file?

Well, open("filename.txt").readlines() gives you a list of all the lines in a txt file, which might not be sentences, depending on the text file is structured.  If you really want to interpret the text file as a collection of sentences, some parsing might be involved. What is a sentence? A sequence of words ending with a dot? With a question mark? How do quotes play a role in this?

Did you have a specific sentence (or line) in thought? The first line? The last line? A random line somewhere in between?

Until then we have to guess, and my E.S.P. is notoriously bad.

Greetings,

-- 
"Learn to value yourself, which means: fight for your happiness."  - Ayn Rand      




More information about the Python-list mailing list