我想将这个python代码转换成另一种格式的文件,它需要三个参数输入文件,输出文件和百分比值。我在shell脚本中调用了python函数,并且它第一次运行正常,但第二次不起作用。错误是“IOError:[Errno 2]没有这样的文件或目录:'ux_source_2850.txt'。但我很确定这个文件在这个目录中。有人能帮助我吗? 此外,我想知道是否有另一种方式来调用python函数,就像一个编译的c函数,所以我可以与几个参数一起执行函数。IOError:[Errno 2]没有这样的文件或目录:'ux_source_2850.txt
#!/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
!
“但我敢肯定,这个文件是在这个目录中”你真的确定吗?我认为这可能会失败的唯一原因是如果该文件真的不存在。 – CDspace