我试图用这个python代码将一个文件转换成另一种格式,它需要输入文件、输出文件和一个百分比值三个参数。我在shell脚本中调用python函数,它第一次工作正常,但第二次就不行了。错误是“IOError:[Errno 2]没有这样的文件或目录:'ux_source_2850.txt”。但我很确定这个文件在这个目录中。有人能帮帮我吗。 另外,我想知道是否有另一种方法来调用python函数,比如编译的c函数,这样我就可以连同几个参数一起执行函数。在
#!/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
!
问题可能出在shell脚本,而不是Python脚本。确保在作为Python脚本输入的行中没有尾随空格。在
更好的是,使用:
相关问题 更多 >
编程相关推荐