Re: python lists and newline character

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Josack

    Re: python lists and newline character

    Gary Herron wrote:
    Support Desk wrote:
    >>
    >Hello all,
    >>
    > I am using os.popen to get a list returned of vpopmail
    >users, something like this
    >>
    >>
    >>
    >x = os.popen('/home/vpopmail/bin/vuserinfo -n -D
    >mydomain.com). readlines()
    >>
    >>
    >>
    >x returns a list, of usernames, and I am trying to append the
    >usernames with the domain like so
    >>
    >>
    >>
    >for line in x:
    >>
    > print line + ‘@’ + domain
    >>
    >>
    >>
    >but instead of getting
    >>
    >>
    >>
    >user@domain.com <mailto:user@do main.com>
    >>
    >>
    >>
    >im getting a newline character like:
    >>
    >user
    >>
    >@domain.com
    >>
    >User
    >>
    >@comain.com
    >>
    >User2
    >>
    >@domain.com
    >>
    >>
    >>
    >>
    >>
    >Is there some way I can get this list without the newline characters
    >being added. or somehow remove the newline characters. Any help would
    >be appreciated.
    >>
    >
    The problem has nothing to do with lists. The readlines() function
    returns each line *with* its newline. To strip it off, use line.strip()
    >
    Gary Herron
    >
    >------------------------------------------------------------------------
    >>
    >--
    >http://mail.python.org/mailman/listinfo/python-list
    >
    --
    http://mail.python.org/mailman/listinfo/python-list
    Also os.popen is deprecated. You should probably learn subprocess.

    Thanks,
    Gary M. Josack
Working...