入力ファイル、出力ファイル、およびパーセンテージ値の 3 つの引数を必要とするこの python コードを使用して、ファイルを別の形式に変換しようとしています。シェル スクリプトで python 関数を呼び出すと、最初は正常に機能しますが、2 回目は機能しません。エラーは「IOError: [Errno 2] No such file or directory: 'ux_source_2850.txt」です。しかし、このファイルがこのディレクトリにあると確信しています。誰かが私を助けてくれませんか。また、コンパイルされたC関数のようにPython関数を呼び出す別の方法があるのではないかと思っているので、いくつかの引数と一緒に関数を実行できます。
#!/usr/bin/env python
def convertfile(file1,file2,percentage):
with open(file1, "r+") as infile, open(file2, "w+") as outfile:
outfile.write('lon lat Ve Vn Se Sn Cen Site Ref\n')
for line in infile.readlines():
line = line.strip()
new_line=line + " "+percentage+" "+percentage+" "+'0.05 stat(0,0) test1'+'\n'
outfile.write(new_line)
file1=raw_input()
file2=raw_input()
percentage=raw_input()
convertfile(file1,file2,percentage)
#!/bin/bash
infile1=ux_source_$j.txt
outfile1=ux_$j.txt
percentage1=`sort biggest_z_amp | tail -1 | awk '{print $1*2e4}'`
../convertfile.py<<!
$infile1
$outfile1
$percentage1
!
infile2=uy_source_$j.txt
outfile2=uy_$j.txt
../convertfile.py<<!
$infile2
$outfile2
$percentage1
!