test.py内容如下:
#!/usr/local/bin/python
import sys
for line in sys.stdin:
ss = line.strip().split('\t')
key = ss[0]
val = ss[1]
print "%s\t%s" % (key, val)
print key + "\t" +val
print '\t'.join([key, val])
1.txt内容如下:
[root@master badou]# cat 1.txt
1 hadoop3 hadoop5 hadoop7 hadoop9 hadoop11 hadoop13 hadoop15 hadoop17 hadoop19 hadoop21 hadoop23 hadoop25 hadoop27 hadoop29 hadoop31 hadoop33 hadoop35 hadoop37 hadoop39 hadoop41 hadoop43 hadoop45 hadoop47 hadoop49 hadoop51 hadoop53 hadoop55 hadoop57 hadoop59 hadoop61 hadoop63 hadoop65 hadoop67 hadoop69 hadoop71 hadoop73 hadoop75 hadoop77 hadoop79 hadoop81 hadoop83 hadoop85 hadoop87 hadoop89 hadoop91 hadoop93 hadoop95 hadoop97 hadoop99 hadoop
运行结果如下:
[root@master badou]# cat 1.txt | python test.py
1 hadoop3
1 hadoop3
1 hadoop3
结论:
print "%s\t%s" % (key, val) 和print key + "\t" +val和print '\t'.join([key, val])的效果一样