Let’s say I have an extremely long string with arguments that I want to create. I know you can create a multiline string with
JavaScript
x
4
1
cmd = """line 1
2
line 2
3
line 3"""
4
But now lets say I want to pass 1, 2, and 3 as arguments.
This works
JavaScript
1
4
1
cmd = """line %d
2
line %d
3
line %d""" % (1, 2, 3)
4
But if I have a super long string with 30+ arguments, how can I possibly pass those arguments in multiple lines? Passing them in a single line defeats the purpose of even trying to create a multiline string.
Thanks to anyone in advance for their help and insight.
Advertisement
Answer
You could abuse the line continuation properties of the parenthesis (
and the comma ,
.
JavaScript
1
7
1
cmd = """line %d
2
line %d
3
line %d""" % (
4
1,
5
2,
6
3)
7