Re: help me debug my "word capitalizer" script

2012-08-23 Thread John Ladasky
On Wednesday, August 22, 2012 3:28:18 AM UTC-7, Kamil Kuduk wrote: > less file.txt | sed -e "s/\b\([a-z]\{4,\}\)/\u\1/g" Say what? Yes, you could do a crazy regex at the Linux prompt. But... will you be able to retain that insane syntax in your head until the NEXT time you need to write somet

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Terry Reedy
On 8/22/2012 10:46 AM, Rebelo wrote: Is it possible to make this script look at a word, see if its first character is capitalized, if capitalized then skip that word. Unicode has two 'capital' concepts: 'uppercase' and 'titlecase'. They are the same for latin chars but not for all alphabets.

Re: help me debug my "word capitalizer" script

2012-08-22 Thread MRAB
On 22/08/2012 09:20, Hans Mulder wrote: [snip] Alternatively, if you want to remove only the line separator, you could do: if line.endswith(linesep): line = line[:-len(linesep)] The 'if' command is only necessary for the last line, which may or may not end in a linesep.

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Rebelo
> Let's move to Bug #2: > > 2. How do I escape the words that are already in uppercase? For example: > > > > The input file has this: > > NASA > > > > The script changes this to: > > Nasa > > > > Is it possible to make this script look at a word, see if its first > > character is cap

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Joel Goldstick
On Wed, Aug 22, 2012 at 9:00 AM, Santosh Kumar wrote: > OK! The bug one fixed. Thanks to Andreas Perstinger. > > Let's move to Bug #2: > 2. How do I escape the words that are already in uppercase? For example: > > The input file has this: > NASA > > The script changes this to: > Nasa > > Is it po

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Santosh Kumar
OK! The bug one fixed. Thanks to Andreas Perstinger. Let's move to Bug #2: 2. How do I escape the words that are already in uppercase? For example: The input file has this: NASA The script changes this to: Nasa Is it possible to make this script look at a word, see if its first character is ca

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Kamil Kuduk
On Wed, Aug 22, 2012 at 12:41 PM, Chris Angelico wrote: > Why less? Why not just redirect input? Yeah, my bad, I somehow used to do it, for grep too, and I know that this is slower > Though, this isn't really on topic for Python. I would still go with regexp, something like: with open('myfile.t

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Chris Angelico
On Wed, Aug 22, 2012 at 8:28 PM, Kamil Kuduk wrote: >> Purpose of the script: >> To capitalize the first letter of any word in a given file, leaving >> words which have 3 or less letters. > > First or all? If first and this is the only purpose of the script you > can easily use sed: > less file.tx

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Kamil Kuduk
> Purpose of the script: > To capitalize the first letter of any word in a given file, leaving > words which have 3 or less letters. First or all? If first and this is the only purpose of the script you can easily use sed: less file.txt | sed -e "s/\b\([a-z]\{4,\}\)/\u\1/g" -- http://mail.python.

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Hans Mulder
On 22/08/12 08:21:47, Santosh Kumar wrote: > Here is the script I am using: > > from os import linesep > from string import punctuation > from sys import argv > > script, givenfile = argv > > with open(givenfile) as file: > # List to store the capitalised lines. > lines = [] > for li

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Chris Angelico
On Wed, Aug 22, 2012 at 4:21 PM, Santosh Kumar wrote: > Purpose of the script: > To capitalize the first letter of any word in a given file, leaving > words which have 3 or less letters. > > Bugs: > I know it has many bugs or/and it can be improved by cutting down the > code, but my current focus

Re: help me debug my "word capitalizer" script

2012-08-22 Thread Andreas Perstinger
On 22.08.2012 08:21, Santosh Kumar wrote: with open(givenfile) as file: # List to store the capitalised lines. lines = [] for line in file: # Split words by spaces. words = line.split(' ') The last element in your "words" list will still have a newline characte

help me debug my "word capitalizer" script

2012-08-21 Thread Santosh Kumar
Here is the script I am using: from os import linesep from string import punctuation from sys import argv script, givenfile = argv with open(givenfile) as file: # List to store the capitalised lines. lines = [] for line in file: # Split words by spaces. words = line.s