我有两个文件,' something.txt' ' program.py'
这是我的计划:
#!/usr/bin/python
## your code here
import sys
line = ""
for n in [line for line in sys.stdin.readlines()]:
sys.stdout.write(n.split()[0]+n.split()[9]+'\n')
运行时
$ more something.txt | python program.py
我得到了
199.72.81.556245
unicomp6.unicomp.net3985
199.120.110.214085
burger.letters.com0
199.120.110.214179
burger.letters.com0
burger.letters.com0
163.205.53.1455666
163.205.53.1428219
163.205.53.141204
tiger2.ocs.lsu.edu8677
199.0.2.275866
tornado.umd.edu5494
我想在' n.split()[0]'之间留一个空格。和' n.split()[9]'
199.72.81.55 6245
unicomp6.unicomp.net 3985
199.120.110.21 4085
burger.letters.com 0
199.120.110.21 4179
burger.letters.com 0
burger.letters.com 0
163.205.53.145 5666
163.205.53.142 8219
163.205.53.14 1204
tiger2.ocs.lsu.edu 8677
199.0.2.27 5866
tornado.umd.edu 5494
但
sys.stdout.write(n.split()[0]+' 'n.split()[9]+'\n')
或
sys.stdout.write(n.split()[0]+" "n.split()[9]+'\n')
无效。 有人可以帮忙吗?
答案 0 :(得分:0)
你几乎就在那里,使用它,
sys.stdout.write(n.split()[0]+' '+n.split()[9]+'\n')