Why ' '.some_string is often used ?

Lawrence Oluyede raims at dot.com
Wed Jan 7 14:43:21 CET 2004


"Stéphane Ninin" <stefnin.nospam at yahoo.fr> writes:

> def normalize_whitespace(text):
>     "Remove redundant whitespace from a string"
>     return ' '.join(text.split())
>
> Is there a reason to do instead of just returning join(text.split()) ?

join is a function of string module and it belongs also to
string object. So you can't do join() but you have to do

str = " "
str.join(text.split())

or

import string
string.join(text.split(), " ")

Take a look: http://python.org/doc/current/lib/module-string.html

-- 
Lawrence "Rhymes" Oluyede
http://loluyede.blogspot.com



More information about the Python-list mailing list