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
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.
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.
> 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
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
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
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
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
> 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.
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
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
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
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
13 matches
Mail list logo