Skip to content Skip to sidebar Skip to footer

Python Escape Special Characters In Sys Argv

I have a script that takes sys.argv and the input may contain special characters (semicolon). I just need the input as string, but semicolon messes everything up.. I have: def mysc

Solution 1:

it's not a matter of python, you need to escape it in the calling shell. simply escape quotes as \" and semicolons as \;.

$ python testme.py "With these words she greeted Prince Vasili Kuragin, a man of high rank and importance, who was the first to arrive at her reception. Anna Pavlovna had had a cough for some days. She was, as she said, suffering\" from la grippe; grippe being then a new word in St. Petersburg\""

With these words she greeted Prince Vasili Kuragin, a man of high rank and importance, who was the firstto arrive at her reception. Anna Pavlovna had had a cough forsome days. She was, as she said, suffering" from la grippe; grippe being then a new word in St. Petersburg"

Solution 2:

This is not a python issue, it's a bash issue. Bash thinks the ; (semicolon) is separating a new bash command. You need to escape it.

Post a Comment for "Python Escape Special Characters In Sys Argv"