Any algorithm to preserve whitespaces?

Discussion in 'Python' started by Santosh Kumar, Jan 19, 2013.

  1. I have a working script which takes argv[1] as an input, deassembles
    each line, and then each word. Then after it capitalizes all its word
    (upcases the first letter) and then prints it out on the stdout.

    That script does the capitalization work fine, but, when it reassemble
    the the words, it does it like this:

    lines.append(' '.join(words))

    The biggest problem is, even when the input file has many spaces, it
    strips it down to one.

    A file with this line:

    This line contains many spaces
    becomes:

    This Line Contains Many Spaces


    The whole script will look clumsy here. I have put it up on GitHub,
    here is it: https://github.com/santosh/capitalizr.py/blob/master/capitalizr
    Santosh Kumar, Jan 19, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lie Ryan
    Replies:
    0
    Views:
    130
    Lie Ryan
    Jan 19, 2013
  2. Mitya Sirenef

    Re: Any algorithm to preserve whitespaces?

    Mitya Sirenef, Jan 19, 2013, in forum: Python
    Replies:
    0
    Views:
    135
    Mitya Sirenef
    Jan 19, 2013
  3. Santosh Kumar

    Re: Any algorithm to preserve whitespaces?

    Santosh Kumar, Jan 23, 2013, in forum: Python
    Replies:
    0
    Views:
    94
    Santosh Kumar
    Jan 23, 2013
  4. Peter Otten
    Replies:
    0
    Views:
    89
    Peter Otten
    Jan 23, 2013
  5. Dave Angel
    Replies:
    0
    Views:
    89
    Dave Angel
    Jan 23, 2013
Loading...

Share This Page