Help with Python script
1
0
Entering edit mode
5.2 years ago
imda ▴ 10

Dear all, I am trying to use a program called phyphy. This program runs into python. I would like to create a script that can run in all my files. i. e., in the line e = Extractor("/path/to/FEL.json") the program uses a file in .json format but I have thousands of .json files. So, I want to create a script that can run for all the files that I have stored in several folders.

This is how I run the program into python but this is just for one file.

import phyphy

### Define a FEL Extractor, for example
e = Extractor("/path/to/FEL.json") 
e.extract_csv("fel.csv")  ## save to fel.csv

### tab-delimited output, as fel.tsv
e.extract_csv("fel.tsv", delim = "\t")
python script • 899 views
ADD COMMENT
1
Entering edit mode

Please format your code using the code formatting button: enter image description here

Additionally, it's not clear what you have tried or what in particular you're having trouble with. Looping through files or running a script on many files is fairly straightforward, and there are many, many tutorials on how to do so that can be found with minimal searching.

ADD REPLY
0
Entering edit mode
5.2 years ago
shoujun.gu ▴ 350
   import glob
   files=[]
   for folder in list-of-folders:
      fnames=glob.glob(f'{folder}/*.json')
      files+=fnames

   for f in files:
      your-scripts
ADD COMMENT

Login before adding your answer.

Traffic: 2699 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6