LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-06-2014, 02:57 AM   #1
simhumcon
Member
 
Registered: Dec 2013
Posts: 35

Rep: Reputation: Disabled
python convert output to a list


hello all,

i've been struggling with this issue and im really new to python. i have a linux command that will display output as below

tda
tdb
tdc
tdd

i want to convert above output as a list, such as ('tda', 'tdb', 'tdc', 'tdd')

can that be done in python?? right now, if i try to print list(output), i get as this ['t','d','a','\n','t','d','t','\n',) someone please help!!!!
 
Old 05-06-2014, 03:01 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,110

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
what is the code you wrote?
 
1 members found this post helpful.
Old 05-06-2014, 03:07 AM   #3
simhumcon
Member
 
Registered: Dec 2013
Posts: 35

Original Poster
Rep: Reputation: Disabled
hi there!

actually, here is what i'm doing. i'm issuing a command : td-cli device --list | grep -v "Device List"
this a command from our customized driver in linux machine. so the output that i get is as below

tda
tdb
tdc
tdd

i'm trying to make this as a list so i can actually see how many tdx didn't show up. right now, when i do this :
#
DIMMs_list_current = commands.getoutput('td-cli device --list | grep -v "Device List"')
for DIMMs in DIMMs_list_current :
print DIMMs
#

when i do this, i get
t
d
a

t
d
b

t
d
c

t
d
d

i want the output to be as below
tda
tdb
tdc
tdd
 
Old 05-06-2014, 03:24 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,110

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
Code:
for DIMMs in DIMMs_list_current.split('\n'):
- or -
for DIMMs in DIMMs_list_current.split(' '):
should work
 
1 members found this post helpful.
Old 05-06-2014, 03:27 AM   #5
simhumcon
Member
 
Registered: Dec 2013
Posts: 35

Original Poster
Rep: Reputation: Disabled
thank you very much!!!!!!!!!!!!
 
Old 05-06-2014, 03:47 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,110

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
glad to help you
if you were Happy with solution ... please mark thread as [SOLVED]
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Convert map(None, list1, list2) from Python 2.x to Python 3.x grail Programming 2 04-06-2010 09:46 AM
List 4 names from users list and output them to fbusers in numbered ascending order? fezzie Programming 4 02-10-2010 02:05 PM
Convert python script to windows executable ankit_mcgill Linux - Newbie 4 10-05-2008 02:21 AM
convert while(<>) from perl to python bardinjw Programming 2 04-13-2006 09:21 AM
convert string to integer with python Kanaflloric Programming 2 05-27-2005 12:04 PM


All times are GMT -5. The time now is 08:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration