Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

stdout

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?

like image 738
Vladan Avatar asked Feb 25 '23 11:02

Vladan


1 Answers

sys.stdout.write(str(i) + sys.argv[1].decode("string_escape"))
like image 82
taskinoor Avatar answered Mar 12 '23 12:03

taskinoor