文章目录
python调用python脚本
想循环执行某个脚本
os.system(command)
demo:
import glob
import os
def operation(input_txt, output_json, output_csv):
os.system(
f"python extract_features.py "
f"--input_file='{input_txt}' "
f"--output_file='{output_json}' "
"--vocab_file=./multi_cased_L-12_H-768_A-12/vocab.txt "
"--bert_config_file=./multi_cased_L-12_H-768_A-12/bert_config.json "
"--init_checkpoint=./multi_cased_L-12_H-768_A-12/bert_model.ckpt.index "
"--do_lower_case=False "
"--layers=0,1,2,3,4,5,6,7,8,9,10,11 "
"--max_seq_length=512 "
"--batch_size=64")
os.system(f"python jsonl2csv.py '{output_json}' '{output_csv}'")
positive_count = 0
negative_count = 0
print('Reading positive data ...')
for fileName in glob.glob(os.path.join('promoter', '*.{}'.format('seq'))):
positive_count += 1
name = fileName.split("/")[1][:-4]
print(name)
input_txt = fileName
output_json = f"./dataset/output_json/promoter/{name}.json"
output_csv = f"./dataset/promoter/{name}.csv"
operation(input_txt, output_json, output_csv)
print('Finish loading positive data', positive_count)
print('Reading negative data ...')
for fileName in glob.glob(os.path.join('non_promoter', '*.{}'.format('csv'))):
negative_count += 1
name = fileName.split("/")[1][:-4]
print(name)
input_txt = fileName
output_json = f"./dataset/output_json/non_promoter/{name}.json"
output_csv = f"./dataset/non_promoter/{name}.csv"
operation(input_txt, output_json, output_csv)
print('Finish loading positive data', negative_count)
注意:
当参数有空格时,应该使用''
把参数包裹,不然会解析成多个参数。