output from external commands

J

James Colannino

Hey everyone. First off, I'm new to the list. I had had a little bit
of experience with Perl before discovering Python. The more Python I
learn, the more I love it :) I just have a quick question to ask. I
know that this is probably a simple question, but I've been googling
around, and partly because I'm not sure exactly what to search for, I've
been unsuccessful at finding an answer. What I'd like to do is be able
to take the output of an external command and assign it as an array of
strings. So, for example, in Perl I could do something like:

@files = `ls`;

So I guess I'm looking for something similiar to the backticks in Perl.
Forgive me if I've asked something that's a bit basic for this list.
Any help would be greatly appreciated :) Thanks very much in advance.

James
 
M

Mike Meyer

James Colannino said:
Hey everyone. First off, I'm new to the list. I had had a little bit
of experience with Perl before discovering Python. The more Python I
learn, the more I love it :) I just have a quick question to ask. I
know that this is probably a simple question, but I've been googling
around, and partly because I'm not sure exactly what to search for,
I've been unsuccessful at finding an answer. What I'd like to do is
be able to take the output of an external command and assign it as an
array of strings. So, for example, in Perl I could do something like:

@files = `ls`;

So I guess I'm looking for something similiar to the backticks in
Perl. Forgive me if I've asked something that's a bit basic for this
list. Any help would be greatly appreciated :) Thanks very much in
advance.

This is a scripting language feature. Python doesn't have direct
support for it, any more than C++ does. To get that functionality, you
want to use either the os.popen function, or - preferable, but only
available in newer Pythons - the subprocess module.

<mike
 
J

James Colannino

Mike said:
This is a scripting language feature. Python doesn't have direct
support for it, any more than C++ does. To get that functionality, you
want to use either the os.popen function, or - preferable, but only
available in newer Pythons - the subprocess module.

Thanks.

James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top