strip newline from string
Ian Clark
turbana at gmail.com
Sat Apr 28 20:25:37 EDT 2007
On 4/28/07, James <oscartheduck at gmail.com> wrote:
[snip]
> username = getuser()
> string.strip
> (username)
> print "username is %s" % username
[snip]
>
>
> 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.
Ian
More information about the Python-list
mailing list