python的字符串拼接代码:
场景:给定一个文件,这个文件中有若干条关系元组数据,选出其中几列拼接为一个列,然后将这个列加到列的最末尾,写通配程序
注意:命令行参数的输入处理,文件处理,字符串处理函数
#!/usr/bin/python
#!/usr/bin
# Filename: extract_and_merge.py
import sys;
def handle_the_record():
file_for_read=open(str(sys.argv[1]));
file_for_write=open(str(sys.argv[2]),'w');
splits=len(sys.argv)-3;
#from 0 to the split_change-th column
split_change=[];
for i in range(0,splits):
split_change.append(int(sys.argv[3+i]));
line_sum='';
while True:
line='';
line=file_for_read.readline();
if line=='':
file_for_read.close();
file_for_write.close();
break;
if ord(line[len(line)-1])==10 and ord(line[len(line)-2])==14:
line_sum+=line;