Shell Commands in Python Code

  • Thread starter Sara Khalatbari
  • Start date
S

Sara Khalatbari

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
 
P

Paul Watson

Sara Khalatbari said:
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,
 
F

F. Petitjean

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.
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top