IOError:[Errno 2]没有这样的文件或目录:'ux_source_2850.tx

2024-09-28 01:24:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用这个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                                                                   
!              

Tags: 文件函数txtsourceinput参数rawline

热门问题