LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 01: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, 02:01 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,910

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
what is the code you wrote?
 
1 members found this post helpful.
Old 05-06-2014, 02: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, 02:24 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,910

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
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, 02:27 AM   #5
simhumcon
Member
 
Registered: Dec 2013
Posts: 35

Original Poster
Rep: Reputation: Disabled
thank you very much!!!!!!!!!!!!
 
Old 05-06-2014, 02:47 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,910

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


Reply



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 08:46 AM
List 4 names from users list and output them to fbusers in numbered ascending order? fezzie Programming 4 02-10-2010 01:05 PM
Convert python script to windows executable ankit_mcgill Linux - Newbie 4 10-05-2008 01:21 AM
convert while(<>) from perl to python bardinjw Programming 2 04-13-2006 08:21 AM
convert string to integer with python Kanaflloric Programming 2 05-27-2005 11:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:34 AM.

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
Open Source Consulting | Domain Registration