Python 使用标准输出的程序中的间距
我有两个文件,“something.txt”“program.py” 以下是我的节目:Python 使用标准输出的程序中的间距,python,stdout,spacing,Python,Stdout,Spacing,我有两个文件,“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
#!/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
我明白了
我希望在“n.split()[0]”和“n.split()[9]”之间有一个空格
但是
或
这是无效的。
有人能帮忙吗?你快到了,用这个
sys.stdout.write(n.split()[0]+' '+n.split()[9]+'\n')
sys.stdout.write(n.split()python whatch@tripleee是的,我很清楚这一点,但讲师希望我们练习使用管道|即使如此,像more
这样的交互式程序相对于更传统的无用cat
的价值是负面的-更复杂、更昂贵,但没有实际的好处,因为你没有也确实无法使用它的功能。
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')
sys.stdout.write(n.split()[0]+' '+n.split()[9]+'\n')