品牌网站建设价位,腾讯云服务器网站域名备案,app和微网站的区别是什么,搞好姓氏源流网站建设我对Python很陌生,对stdin stdout方法甚至更新.不过,我需要使我的脚本可用于UNIX命令,以便例如使用我的脚本一次处理2个输入文件.该脚本与命令行参数完美配合#xff1a;newlist []def f1()....def f2(input_file):vol_id sys.argv[3]for line in input_file:if ... :line …我对Python很陌生,对stdin stdout方法甚至更新.不过,我需要使我的脚本可用于UNIX命令,以便例如使用我的脚本一次处理2个输入文件.该脚本与命令行参数完美配合newlist []def f1()....def f2(input_file):vol_id sys.argv[3]for line in input_file:if ... :line line.replace(abc,def)line line.replace(id, idvol_id)....newlist.append(line)return newlistdef main():if len(sys.argv) 4:print usage: ./myscript.py [file_in... file_out... volume_id]sys.exit(1)else:filename sys.argv[1]filename_out sys.argv[2]tree etree.parse(filename)extract(tree)input_file open(filename, rU)change_class(input_file)file_new open(filename_out, w)for x in newlist:if in x:x x.replace(, )printfile_new, x当我尝试向其添加stdin stdout时,首先遇到一个问题,即首先读取相同的输入文件,并且由于这个原因进行了一些修改,因此实际上只能打开一次.这是我修改过的main()filename sys.argv[1]filename_out sys.argv[2]if filename -:filename sys.stdinelse:input_file open(filename, rU)if filename_out -:filename_out sys.stdoutfile_new filename_outelse:file_new open(filename_out, w)input_file open(filename, rU)tree etree.fromstring(input_file)extract(tree)change_class(input_file)for x in newlist:if in x:x x.replace(, )printfile_new, x然后我像这样运行我的脚本./myscript.py–volumeid输出文件我得到了这个错误信息Traceback (most recent call last):File ./myscript.py, line 191, in main()File ./myscript.py, line 175, in maininput_file open(filename, rU)TypeError: coercing to Unicode: need string or buffer, file found我究竟做错了什么