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

Válas Péter sulinet at postafiok.hu
Fri Jun 10 09:16:08 CEST 2011


A few hints to make it more efficient:

2011/6/10 B G <compbiocancerresearcher at gmail.com>

> 1) Create a script that gives me a list of all the filenames in the folder:
> I managed to do the following:
> path = "...\\Leukemia_Project"
>
Use / in path instead of \\, it will work in all environments, not just
Windows.  One of the advantages of Python is that most of its code is
platform independent; it would be a pity to throw this benefit away, and you
don't know where and for what purpose will you use your scripts later.

i = 0
>
What do you use i for? Is it necessary?


> 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)
>
I would not do this unless it is much easier than programming it or I am
forced to do so with a machine gun. :-)
Instead of print and copy and paste and save, you should write the whole
stuff into a file. Processing it in Excel may be worth if you cannot exactly
specify the things you want to remove. If they are well specified, do it in
Python. As far as i understand, you have a great amount of data, and this is
what programming is for. :-)


> 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)
>
Once you preprocessed  the filelist, it can be aither another script or the
same. It depends on whether you always run them together, or some of them is
needed alone.

As Alan wrote, IDLE is no interpreter. Personally, I find more comfortable
to write my scripts in Notepad++ and run at command prompt, because IDLE
does not provide line numbers :-((, and I suspect that it makes a great load
for the computer (on my weak machine it often looses socket and won't start
any more).


2011/6/10 Alan Gauld <alan.gauld at btinternet.com>

> If the script take a filename as an input parameter you can likely do
>
> python myfile.py *.*
>
> from the OS command prompt.
>
Using Windows you may omit python, too. myfile.py is enough for a well
educated Windows. :-)

Péter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110610/1bdab5c5/attachment.html>


More information about the Tutor mailing list