本人这阵子刚刚接触python 老师给了一个任务。在linux下输入命令行参数类似 python file1 file2 这样的命令,意思是将file1处理后的文件写入file2中。以下是我的代码(刚刚接触写的不好请轻喷):
#!/usr/bin/python
# coding=utf-8
import sys
def function():
file1=argv[1]
file2=argv[2]
f1=open(file1,'r')
f2=open(file2,'w')
l=f1.readlines()
l=[x.split(' ') for x in l]
f1.close
l=[[int(x[0]),int(x[1]),int(x[2]),int(x[3]),int(x[4]),int(x[5]),int(x[6]),int(x[7]),int(x[8])] for x in l]
for eachline in l:
eachline.sort()
f2.write(str(eachline))
f2.write('\n')
if __name__=='__main__':
if len(sys.argv)!=3:
print ("Usage: python input_file output_file")
print ("commond: ./file.py input_file output_file")
exit(1)
file1=sys.argv[1]
file2=sys.argv[2]
function()
请大神帮我改一下,这个程序的过程就是将file1中的数字读取排序并保存到file2中。不吝赐教!!!
#!/usr/bin/python
# coding=utf-8
import sys
def function():
file1=argv[1]
file2=argv[2]
f1=open(file1,'r')
f2=open(file2,'w')
l=f1.readlines()
l=[x.split(' ') for x in l]
f1.close
l=[[int(x[0]),int(x[1]),int(x[2]),int(x[3]),int(x[4]),int(x[5]),int(x[6]),int(x[7]),int(x[8])] for x in l]
for eachline in l:
eachline.sort()
f2.write(str(eachline))
f2.write('\n')
if __name__=='__main__':
if len(sys.argv)!=3:
print ("Usage: python input_file output_file")
print ("commond: ./file.py input_file output_file")
exit(1)
file1=sys.argv[1]
file2=sys.argv[2]
function()
请大神帮我改一下,这个程序的过程就是将file1中的数字读取排序并保存到file2中。不吝赐教!!!