passing \n (new line) on stdout throught sys argument

我的未来我决定 提交于 2019-12-18 06:59:28

问题


This is elementary I guess:

Let's consider this snippet:

for i in range(3):
    sys.stdout.write(str(i) + '\n')

out:

0
1
2

and this:

for i in range(3):
    sys.stdout.write(str(i) + sys.argv[1])

out (after passing \n as argument):

0\n1\n2\n

So, how can I pass new-line as argument?


回答1:


sys.stdout.write(str(i) + sys.argv[1].decode("string_escape"))


来源:https://stackoverflow.com/questions/5715414/passing-n-new-line-on-stdout-throught-sys-argument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!