January 17th, 2013, 04:50 PM
I want to create a simple copy/past program that will read a line of plain text, remove pre-defined words or unwanted text and then reformat the remaining text. Is this something that could easily achieved with Python?
I have no previous programming experience so I going to try and self -teach, I was just wondering if Python was a good option?
January 17th, 2013, 11:27 PM
It's fairly easy in python. Run this code as an example. For a real application I'd want to be more careful about punctuation and capital letters to start sentences and two spaces or more separating sentences. Finding words was easy, removing some words was easy, and reformatting was easy.
text = '''As she was a long time before she found
her work-case, her father grew impatient; she did not
answer, but as she sewed she pricked her fingers, which
she then put to her mouth to suck them. Charles was
surprised at the whiteness of her nails. They were shiny,
delicate at the tips, more polished than the ivory of
Dieppe, and almond-shaped. Yet her hand was not
beautiful, perhaps not white enough, and a little hard at
the knuckles; besides, it was too long, with no soft
inflections in the outlines. Her real beauty was in her eyes.'''
''' remove 3 letter "words" '''
words = s.split()
return ' '.join(word for word in words if len(word) != 3)
[/code] are essential for python code and Makefiles!