qa

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Sep 17 17:59:06 EDT 2007


En Mon, 17 Sep 2007 18:15:29 -0300, Shawn Minisall <trekker182 at gmail.com>  
escribi�:

> I'm trying to get a space in between these two strings but it's ignoring
> the space in between when it prints.
>
>  >>> string.capwords (string.join([s1 + " " + s2])) * 3
> 'Spam Ni!Spam Ni!Spam Ni!'
>  >>>

It doesn't matter how many spaces you put in between, capwords will  
collapse all of them into a single space.

py> from string import capwords
py> help(capwords)
Help on function capwords in module string:

capwords(s, sep=None)
     capwords(s, [sep]) -> string

     Split the argument into words using split, capitalize each
     word using capitalize, and join the capitalized words using
     join. Note that this replaces runs of whitespace characters by
     a single space.

py> capwords("  hello      world    ")
'Hello World'
py> ' '.join([capwords("  hello      world    ")] * 3)
'Hello World Hello World Hello World'

Is that what you want?

-- 
Gabriel Genellina




More information about the Python-list mailing list