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

2019-01-28 06:42发布

问题:

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"))


标签: python stdout