python - [Variable as a String]>Special characters printed -
this question has answer here:
- windows path in python 2 answers
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
Post a Comment