[Biopython] using a function on a batch of files

Eric Talevich eric.talevich at gmail.com
Mon Jun 27 23:18:10 UTC 2011


Hi Dilara,

If the glob module doesn't do what you want, then os.listdir might be it:
http://docs.python.org/library/os.html#os.listdir

Usage:
for fname in os.listdir("path/to/files/"):     print fname

Cheers,
Eric

On Mon, Jun 27, 2011 at 6:33 PM, Dilara Ally <dilara.ally at gmail.com> wrote:

> Hi All
>
> I'm a newbie to python and I'm interested in using a function on a batch of
> files.
>
> I know that in R, you can set the working directory to the directory of
> interest.  Is there a way to do this in Python?  This would allow me to
> access files that were in a different location than where the script file
> is.  The reason I would be interested to do this is that I have a function
> that I want to apply to 400 different files.  If I were scripting in R
> (which I am familiar with) I could use the fn list.files that would list the
> files in the directory.  Then I could read them in one by one with a loop.
>  Apply the function and then write the files to a different directory.
>
> What is the best way to do this in python?
>
> Thanks for the help.
>
> Cheers, Dilara
> ______________________________**_________________
> Biopython mailing list  -  Biopython at lists.open-bio.org
> http://lists.open-bio.org/**mailman/listinfo/biopython<http://lists.open-bio.org/mailman/listinfo/biopython>
>



More information about the Biopython mailing list