Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: python lists and newline character

Reply
Thread Tools

Re: python lists and newline character

 
 
Gary Josack
Guest
Posts: n/a
 
      07-29-2008
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
>>
>>
>>
>> <private.php?do=newpm&u=>
>>
>>
>>
>> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
removing newline character from the buffer read by fgets junky_fellow@yahoo.co.in C Programming 16 11-28-2006 10:44 PM
remove the last character or the newline character? Daniel Mark Python 6 09-28-2006 02:40 PM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM
Reverse Newline character? 3strands@gmail.com C++ 6 09-17-2005 05:04 PM
NEWLINE character problem Dragos Chirila Python 1 01-30-2004 03:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57