【发布时间】:2012-03-24 08:28:02
【问题描述】:
我有一个使用 sys.argv 的脚本,并且输入可能包含特殊字符(分号)。我只需要输入字符串,但分号会搞砸一切..
我有:
def myscript(text)
print text
a = myscript(sys.argv[1])
print a
我试试:
>> python script.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 first to arrive at her reception. Anna Pavlovna had had a cough for some days. She was, as she said, suffering'
None
bash: grippe: command not found
我只想将整个字符串放入脚本中,不管里面是什么..
我试过了:
a = myscript(repr(sys.argv[1]))
a = myscript(str(sys.argv[1]))
【问题讨论】:
标签: python string bash command-line argv