Skip to content
Advertisement

How can I run a python script on many files to get many output files?

I am new at programming and I have written a script to extract text from a vcf file. I am using a Linux virtual machine and running Ubuntu. I have run this script through the command line by changing my directory to the file with the vcf file in and then entering python script.py.

My script knows which file to process because the beginning of my script is:

JavaScript

The script puts the information I need into a list and then I write it to outputfile. However, I have many input files (all .vcf) and want to write them to different output files with a similar name to the input (such as input_processed.txt).

Do I need to run a shell script to iterate over the files in the folder? If so how would I change the python script to accommodate this? I.e writing the list to an outputfile?

Advertisement

Answer

I would integrate it within the Python script, which will allow you to easily run it on other platforms too and doesn’t add much code anyway.

JavaScript

To output the resulting files in a separate directory I would:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement