strip newline from string
turbana at gmail.com
Sun Apr 29 02:25:37 CEST 2007
On 4/28/07, James <oscartheduck at gmail.com> wrote:
> username = getuser()
> 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!
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