How to run multiple lines using python -c -


i need use python -c remotely run code, works when use:

python -c "a=4;print a" 4 

or

python -c "if true:print 'ye'" 

but python -c "a=4;if a<5:print 'ye'" generate error:

file "<string>", line 1     a=4;if a<5:print 'ye'     syntaxerror: invalid syntax 

what should make work, advice?

enclose in single quotes , use multiple lines:

python -c ' = 4 if < 5:     print "ye" ' 

if need single quote in code, use horrible construct:

python -c ' = 4 if < 5:     print '\''ye'\'' ' 

this works because unix shells not interpret between single quotes—so have python code right until need single quote. since it’s uninterpreted, can’t escape quote; rather, end quotation, insert literal quotation mark (escaped, won’t interpreted start of new quote), , finally quote put uninterpreted-string state. it’s little ugly, works.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -