简体   繁体   English

将 sys.stdout.write 转换为在 python 中打印

[英]convert sys.stdout.write to print in python

I'm using a python code with the following code:我正在使用带有以下代码的 python 代码:

sys.stdout.write("{}\t".format(leaf_distances[n][m]))

I just wondered if someone knew a way to replace sys.stdout.write by a print argument?我只是想知道是否有人知道用print参数替换sys.stdout.write的方法? So far I tried:到目前为止,我尝试过:

print("{}\t".format(leaf_distances[n][m]))

but it does not seem to be the same thing.但这似乎不是一回事。

The closest equivalent is print that does not add a line break at the end of the output.最接近的等价物是在 output 末尾不添加换行符的print New-style formatting:新型格式:

print(f"{leaf_distances[n][m]}\t", end="")

Old-style formatting:旧式格式:

print("{}\t".format(leaf_distances[n][m]), end="")

You'd want你会想要

print(str(leaf_distances[n][m]), end="\t")

for an equivalent.为等价物。

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

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