String help

Paul McGuire ptmcg at
Wed Jun 23 23:09:51 CEST 2004

"Rigga" <Rigga at> wrote in message
news:pan.2004. at
> Hi,
> I am new to python and am working on a script that parses a file and loads
> the results in to variables for processing.  I am having problems when it
> comes to data in the file that wraps over two lines i.e.
> las -
>         lomas
> What i want to be able to do is to some how strip all the spaces from it
> so while it is contained as a variable so it equal 'las - lomas'
> How do I go about doing this? I have tried it using the
> string.strip(myvariable,"") however that doesnt appear to do anything.
> Any help appreciated
> Rigga
Try combining split() and join(), something like:

testdata = """
this is
some data
    that spans
       multiple -


print " ".join( testdata.split() )


this is some data that spans multiple - lines

This even handles tabs, and removes trailing whitespace.
-- Paul

More information about the Python-list mailing list