You are not logged in.

#1 2009-08-26 17:52:13

B4RR13N705
Member
Registered: 2009-06-08
Posts: 87

Save a line as multiple variables in Python

Hi, i have a little doubt. For example. i write:

import os
os.system('whereis lmms')

And that returns:

lmms: /usr/bin/lmms /usr/lib/lmms /usr/include/lmms /usr/share/lmms /usr/share/man/man1/lmms.1.gz

And i want to save all that paths into diferent variables, so i get something like this:

a= '/usr/bin/lmms' 
b = '/usr/lib/lmms'
c = '/usr/include/lmms'
d = '/usr/share/lmms'
e = '/usr/share/man/man1/lmms.1.gz'

Last edited by B4RR13N705 (2009-08-26 17:52:40)


OS -----> Arch Linux     DE -----> KDE4
CPU ---> 2.66GHz         RAM ---> 512 MB
SWAP -> 2 G                / -------> 10 G
/home -> 50 G             /boot ---> 64 MB

Offline

#2 2009-08-26 18:10:14

Crows
Member
From: Wales
Registered: 2008-09-05
Posts: 92

Re: Save a line as multiple variables in Python

Something like this should do it:

cmd = os.popen('whereis lmms')
lmms = cmd.read() #Get the output as a string.
cmd.close()
lmms = lmms.split() #Split the output at each space. Creates a list.
lmms = lmms[1:] #Removes the lmms: bit at the beginning.

You can access each path now by using lmms[0], lmms[1] etc. You should look into using the subprocess module instead, though - this method is deprecated.

Last edited by Crows (2009-08-26 18:10:33)

Offline

Board footer

Powered by FluxBB