python/bash how to escape character '!'
I am try to run in Python this
c.run('sqlcmd -U nrv -P PP!asword -Q "select top 3 * from sys.databases"', pty = True)
code in brackets - bash code
it works in terminal in that manner:
sqlcmd -U nrv -P PP\!asword -Q "select top 3 * from sys.databases"
in genereal i try nothing meaningful
CodePudding user response:
Have you tried simply prefixing the "!" with "\" inside your single-quotes in the first form of the equation ? Single-quotes are meant to be taken as literals, so the backslash will be passed thru, exactly as your command-line attempt.
CodePudding user response:
has answer!
c.sudo(r'''sqlcmd -U nrv -P PP!asword -Q "select top 3 * from sys.databases"''')
(in that case I've changed run to sudo because sufficient privileges)
so, I newbie in Python, and heared about "sсreened" strings - and it simply works.it's even strange that a backslash was not required, because command in brackets - it is a bash, and it requires.