[Tutor] Syntax for Simplest Way to Execute One Python Program Over 1000's of Datasets

B G compbiocancerresearcher at gmail.com
Fri Jun 10 01:26:56 CEST 2011


hmm, thanks for the help.  So I kinda got it working, although from an
efficiency perspective it leaves a lot to be desired.

I managed to do the following:
1) Create a script that gives me a list of all the filenames in the folder:
path = "...\\Leukemia_Project"
i = 0
for (files) in os.walk(path):
    print(files)
    print("\n")
    i += 1
2) I manually copy and paste the resulting list from the IDLE interpreter
into a .txt file
3) Open the .txt file in Excel, remove the few lines I don't need (ie single
quotes, etc)
4) Write another python script to print the result from step 3 in a new txt
file, where each filename has its own row (pretty easy to do b/c all
separated by the tab in the original txt file)
5)Put a for loop around my original python script that takes as input each
line from the result of step 4.

As it stands it is painfully awkward, but it works and has already saved me
a lot of aggravation...


On Thu, Jun 9, 2011 at 4:07 PM, Walter Prins <wprins at gmail.com> wrote:

>
>
> On 9 June 2011 20:49, B G <compbiocancerresearcher at gmail.com> wrote:
>
>> I'm trying to analyze thousands of different cancer datasets and run the
>> same python program on them.  I use Windows XP, Python 2.7 and the IDLE
>> interpreter.  I already have the input files in a directory and I want to
>> learn the syntax for the quickest way to execute the program over all these
>> datasets.
>>
>> As an example,for the sample python program below, I don't want to have to
>> go into the python program each time and change filename and countfile.  A
>> computer could do this much quicker than I ever could.  Thanks in advance!
>>
>
> OK, so make a function of the current program logic for a single filename,
> and make the base filename a parameter to that function.  Then write another
> function (or main program) that iterates over your directory tree and calls
> the processing function for each input file.  See documentation for module
> os, specifically os.walk().  (See here:
> http://docs.python.org/library/os.html )
>
> If that doesn't get you going then post back again.
>
> Walter
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110609/65901aff/attachment.html>


More information about the Tutor mailing list