nested - Python: Nest more than two types of quotes -


is possible nest more 2 types of quotation signs? mean know ' , " if need more? allowed:

subprocess.popen('echo "var1+'hello!'+var2"', shell=true) 

you can use triple-quotes avoid kind of problem nested single quotes:

subprocess.popen('''echo "var1+'hello!'+var2"''', shell=true) 

in case want use same triple-quotes both delimiter and inside string have escape quotes in string:

'''some\'\'\'triple quotes\'\'\'''' -> "some'''triple quotes'''" 

alternatively can rely on fact interpreter concatenate consecutive string literals, , use different quotes different parts of string:

subprocess.popen('echo "var1+' "'hello!'" '+var2"', shell=true) 

note in way can mix raw strings non-raw strings:

in [17]: print('non\traw' r'\traw' 'non\traw') non     raw\trawnon     raw 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -