python - [Variable as a String]>Special characters printed -


this question has answer here:

i'm facing strange situation..after setting variable string, try print variable , string caracter replaced special caracter..

file_version_cmd="wmic datafile name='c:\\\program files (x86)\\\citrix\\\ica client\\\4.1\\\wfcrun32.exe'" print(file_version_cmd) 

output of print : wmic datafile name='c:\program files (x86)\citrix\ica client\♦.1\wfcrun32.exe'

"..4.1.." replaced "..♦.1.."

thanks help

you have '\\\4.' in string created non-printable bytes '\4' using \ooo octal value escape sequence. digits interpreted octal numbers.

the default \xhh syntax used represent value in hexadecimal.

you can rewrite string using raw string literal :

file_version_cmd = r"wmic datafile name='c:\program files (x86)\citrix\ica client\4.1\wfcrun32.exe'" 

or

file_version_cmd = "wmic datafile name='c:\\program files (x86)\\citrix\\ica client\\4.1\\wfcrun32.exe'" 

both of above code snippets result in :

wmic datafile name='c:\program files (x86)\citrix\ica client\4.1\wfcrun32.exe' 

also, can use forward slashes of windows apis accept both types of slash separators in filename (if filename path consumed python may not work expected otherwise) :

file_version_cmd = "wmic datafile name='c:/program files (x86)/citrix/ica client/4.1/wfcrun32.exe'" 

you can refer this documentation if want learn more python lexical analyzer.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -