简体   繁体   English

在python中并排打印文件

[英]print file side by side in python

Dear experts i have a programme that callulate x and y and print x and y by the command print(x,y) as follows亲爱的专家,我有一个程序可以调用 x 和 y 并通过命令 print(x,y) 打印 x 和 y,如下所示

[2.63732473e-002 6.95547303e-005 1.83437361e-007 4.83776370e-010
 1.27583713e-012 3.36458575e-015 8.87257918e-018 2.33965401e-020
 6.16901626e-023 1.62648985e-025 4.28780820e-028 1.13020771e-030]
[2.97870294e-033 7.84889062e-036 2.06774505e-038 5.44613117e-041
 1.43405459e-043 3.77498976e-046 9.93370767e-049 2.61308006e-051
 6.16901626e-023 1.62648985e-025 4.28780820e-028 1.13020771e-030]

but i want to print x and y in just two column as follows但我想在如下两列中打印 x 和 y

  x                        y
2.63732473e-002          2.97870294e-033
6.95547303e-005          7.84889062e-036
1.83437361e-007          2.06774505e-038
4.83776370e-010          5.44613117e-041
1.27583713e-012          1.43405459e-043 
3.36458575e-015          3.77498976e-046
8.87257918e-018          9.93370767e-049
2.33965401e-020          2.61308006e-051
6.16901626e-023          6.16901626e-023 
1.62648985e-025          1.62648985e-025 
4.28780820e-028          4.28780820e-028
1.13020771e-030          1.13020771e-030
    

However i tried print(str(x[:,None]),str(y[:,None])) but it still print vertically instead of side by side.hope some expert will help me.Thanks.但是我试过print(str(x[:,None]),str(y[:,None]))但它仍然垂直打印而不是并排打印。希望有专家能帮助我。谢谢。

You can use zip and join :您可以使用zip加入

Use str.format() on a number with "{:e}" as str to format the number in scientific notation.在带有“{:e}”的数字上使用 str.format() 作为 str 以科学记数法格式化数字。

print("\n".join(f"{i:e}   {j:e}" for i, j in zip(x, y)))

You can use \\t to format a tabbing.您可以使用\\t来格式化选项卡。 For example:例如:

print("%d\t\t%d" % (x, y))

All you need is:所有你需要的是:

print(x,y,'\\n')打印(x,y,'\\n')

What you need to do is iterate simultaneously on both lists and print the equivalent field like so:您需要做的是同时在两个列表上迭代并打印等效字段,如下所示:

print(f'x        y')
for i in range(len(x)):
   print(f'{x[i]}        {y[i]}')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM