[Tutor] Invoking bash from within a python program

joe_schmoe geek_show at dsl.pipex.com
Sat Aug 13 18:18:22 CEST 2005

Hi Pythoneers

I'm sure that somewhere in the dim and distant past this was asked, but 
I'll be b***ered if I can find reference to it, and google searches 
haven't been too illuminating yet. Anyway, how do I call bash to run a 
program - e.g. slocate - from within a python program. I believe that I 
have to import the OS first (or do I?) and I was thinking something like:

sh slocate file_name > python_defined_list

This is to populate a list which would then become the filename list for 
the remove file command to iterate through sequentially and delete, as in:

for i in python_defined_list:
	rm -fr i

How the heck do I set that kind of interaction between bash and python 
and the user home directory content up?

Any thoughts?


More information about the Tutor mailing list