strip newline from string

Ian Clark turbana at
Sun Apr 29 02:25:37 CEST 2007

On 4/28/07, James <oscartheduck at> wrote:
>  username = getuser()
>  string.strip
> (username)
>  print "username is %s" % username
> The autoconf.txt contains two lines, which first has an ip address and
> second a username. The problem I'm having is that the string.strip() doesn't
> appear to be stripping the newline off the username.
> Any ideas? If you need more information, just ask!
> James

string.strip() returns a copy of the string with whitespace removed,
it does not modify it in place. What you really want is:
> username = getuser().strip()

Someone correct me if I'm wrong, but I believe just about all
functions from the string module are deprecated. Use the methods from
the string class. As I'm assuming getuser() returns a string object,
just use the string functions on that directly.


More information about the Python-list mailing list