Python Forum
[Variable as a String]>EscaSpecial characters printed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Variable as a String]>EscaSpecial characters printed
#1
Hello

I'm facing a strange situation..after setting a variable as a string, I try to print that variable and get the string with a caracter replaced by a special caracter.. Sad  

file_version_cmd="wmic datafile where name='C:\\\Program Files (x86)\\\Citrix\\\ICA Client\\\4.1\\\wfcrun32.exe'"
print(file_version_cmd)
Output:
wmic datafile where name='C:\\Program Files (x86)\\Citrix\\ICA Client\♦.1\\wfcrun32.exe'
Thanks for your help
Reply
#2
Seems like the '4' symbol is escaped. I can't try it here cause I have no Windows on my machine. Try to put one more backslash there.

I've reproduced it here too.
When you want to print a '\', escape it. Want to print two '\' - escape both. It's a general rule. '\' is the escape character. When it precedes another character if Python recognises the escape sequence, you get something else. I can't tell why this happens with '4'.
https://docs.python.org/3.5/reference/le...s-literals
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
it's because '\ooo' will give the char with octal value ooo

https://docs.python.org/2/reference/lexi...g-literals
Reply
#4
Right! Why I missed it...  Big Grin
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#5
Just use all \(backslash) the other way(/),the no octal value or other escape characters problems.
>>> s = '\4.1'
>>> s
'\x04.1'
>>> print(s)
.1
>>> # Fix
>>> s = '/4.1'
>>> s
'/4.1'
>>> print(s)
/4.1
>>> s = 'C:/Program Files (x86)/Citrix/ICA Client/4.1/wfcrun32.exe'
>>> print(s)
C:/Program Files (x86)/Citrix/ICA Client/4.1/wfcrun32.exe
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  coma separator is printed on a new line for some reason tester_V 4 490 Feb-02-2024, 06:06 PM
Last Post: tester_V
  doing string split with 2 or more split characters Skaperen 22 2,541 Aug-13-2023, 01:57 AM
Last Post: Skaperen
  Replacing String Variable with a new String Name kevv11 2 791 Jul-29-2023, 12:03 PM
Last Post: snippsat
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,533 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  Need help on how to include single quotes on data of variable string hani_hms 5 2,039 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python r string for variable mg24 3 2,829 Oct-28-2022, 04:19 AM
Last Post: deanhystad
  USE string data as a variable NAME rokorps 1 967 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  How can histogram bins be separated and reduce number of labels printed on x-axis? cadena 1 891 Sep-07-2022, 09:47 AM
Last Post: Larz60+
  Removing Space between variable and string in Python coder_sw99 6 6,297 Aug-23-2022, 01:15 PM
Last Post: louries
  Remove a space between a string and variable in print sie 5 1,787 Jul-27-2022, 02:36 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020