String help

Daniel Yoo dyoo at
Wed Jun 23 22:52:26 CEST 2004

Rigga <Rigga at> wrote:

: 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'

Hi Rigga,

Are you stripping as you're reading the file, line by line, or are you
calling strip() at the very end?  Without seeing code, it's a little
hard to tell what you're doing.

: I have tried it using the string.strip(myvariable,"") however that
: doesnt appear to do anything.

Ah, ok.  string.strip() is deprecated, so you probably shouldn't use

(... And, also, it is being misused.  The delimiter -- the second
argument to string.strip() --- has to be nonempty to have any real

Instead, you can just use the strip() method of strings.  For example:

>>> msg = "     hello world     "
>>> msg.strip()
'hello world'
>>> msg.lstrip()
'hello world     '
>>> msg.rstrip()
'     hello world'


for a comprehensive list of the methods that a string can support.

Good luck!

More information about the Python-list mailing list