You are not logged in.

#1 2005-09-19 18:16:40

giddygiddyBA
Member
From: Montreal
Registered: 2004-12-30
Posts: 66

assign program feedback to varibles in python

what is the equivalent of perl's

$var=qx/command -option/;

in python?

ive tried os.spawnv() and os.popen2(), but its not quite what im looking for....

Offline

#2 2005-09-19 18:35:30

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: assign program feedback to varibles in python

fd = os.popen('ls /home')
lines = string.split(fd.read, 'n')

Offline

#3 2005-09-19 18:37:35

giddygiddyBA
Member
From: Montreal
Registered: 2004-12-30
Posts: 66

Re: assign program feedback to varibles in python

thanks a bunch

Offline

#4 2005-09-20 21:04:05

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: assign program feedback to varibles in python

fd = os.popen('ls /home')
lines = fd.read().splitlines()

arch + gentoo + initng + python = enlisy

Offline

#5 2005-09-20 22:46:24

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: assign program feedback to varibles in python

xerxes2 wrote:
fd = os.popen('ls /home')
lines = fd.read().splitlines()

smartass  big_smile  big_smile

Offline

#6 2005-09-22 12:24:15

sweiss
Member
Registered: 2004-02-16
Posts: 635

Re: assign program feedback to varibles in python

What about

lines = os.popen('ls /home').readlines()

Offline

#7 2005-09-22 17:16:52

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: assign program feedback to varibles in python

that one keep newlines sweiss, at least it did last time i tried it,


arch + gentoo + initng + python = enlisy

Offline

#8 2005-09-22 19:15:58

sweiss
Member
Registered: 2004-02-16
Posts: 635

Re: assign program feedback to varibles in python

Oh, so the other one removes them automatically? Guess you just taught me something really useful smile

Thanks a lot.

Offline

Board footer

Powered by FluxBB