PythonからJavaScriptの関数を使う際の実行速度を改善させたい
PythonからJavaScriptの関数の効率的な使い方を教えてください。
テキスト処理のプログラムをPythonで作成しています。
その際、JavaScriptの関数を使用したい箇所があります。
Pythonのsubprocessモジュールを使い、jscコマンドで
JavaScriptのプログラムを実行しています。
入力と出力はファイルの読み書きで行なっているため、
動作が遅いです。
この実行速度を改善する方法を教えてください。
MacOSを使っています。
以下が作成したコードです。
PythonとJavaScriptのソースコード
Python
1import subprocess 2#処理したい文字列を入力し、JavaScriptの関数で処理した文字列を出力 3def process_txt(string): 4 f = open('tmp_input.txt','w') 5 f.write(string) 6 f.close() 7 8 cmd = 'jsc process_txt.js <tmp_input.txt >tmp_output.txt' 9 subprocess.call(cmd,shell = True) 10 11 f = open('tmp_output.txt','r') 12 s = f.read() 13 f.close() 14 return s
JavaScript
1//process_txt.js 2let input = this.readline(); 3let output = process_txt(input);//この関数を使用したい 4print(output);
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/13 09:50
2019/02/14 07:28