[Tutor] how to specify working directory from within python app?

Alan Gauld alan.gauld at btinternet.com
Thu Sep 20 22:35:24 CEST 2007


"Rob Andrews" <rob.andrews at gmail.com> wrote

> I've got a weekly project here in which I have to take a somewhat
> arbitrary number of input files, create working directories in which
> to process each of them, and call other programs from within the 
> scope
> of those directories.
>
> The source files are in a directory named 'orig' under the project
> root directory. Output of my program is placed in directories nested
> two-deep under the job root in different branches.

You might be able to use the os.walk() function to derive the
list of directories and change ionto them using os.chdir()

> Once my data is in those other directories, I have to call certain
> other 3rd-party programs to act on the data in various ways.

A job for the subprocess module.

> How might I best go about calling these 3rd-party apps? On this
> project, the directories are created dynamically, and there can be
> quite a few.

You can create directories and traverse them and so forth using
the os, os.path and glob modules depending on exactly how you
want to go about things.

Most of these things are covered in my Working with the OS
topic in my tutorial.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list