469,578 Members | 1,886 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

Shell Commands in Python Code

There are a lot of commands that I need to use in my
code & I don't know how to do it

Is there a way to use shell commands in Python code?

__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail
Jul 19 '05 #1
3 1970
start to take a look at the call function of the subprocess module -
see http://docs.python.org/lib/node231.html

Jul 19 '05 #2
"Sara Khalatbari" <sa************@yahoo.com> wrote in message
news:ma**************************************@pyth on.org...
There are a lot of commands that I need to use in my
code & I don't know how to do it

Is there a way to use shell commands in Python code?


Yes, there are many popen() forms that you may wish to investigate. Below
is a brief clip. However, if you can find the functionality already built
into Python, such as globbing filenames, that would be better. It will be
more portable to more systems and probably faster.

x = os.popen("ls -al")
for aline in x.readlines():
print aline,
Jul 19 '05 #3
Le Sat, 7 May 2005 08:55:35 -0700 (PDT), Sara Khalatbari a écrit :
There are a lot of commands that I need to use in my
code & I don't know how to do it

Is there a way to use shell commands in Python code? Python is a scrpting language. So you can substitute most shell scripts
idioms with pythonic ones. A large number of shell scripts can be
replaced with python scripts without any semantic loss.

Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Daven Nair | last post: by
7 posts views Thread by fileexit | last post: by
16 posts views Thread by John Salerno | last post: by
4 posts views Thread by Anastasios Hatzis | last post: by
1 post views Thread by Riccardo Maria Bianchi | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.