特殊字符 $ 未从命令行读取 python
Special character $ not read from command line python
这是我的代码
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("echo")
args = parser.parse_args()
print args.echo
当我尝试从命令行使用 $
传递文本时,它没有被接受。我试图通过在 $
符号之前添加 \
来转义特殊字符,但仍然没有成功。这就是我 运行 代码
的方式
python test.py Sample$how
Sample
我在 windows 上,我已经厌倦了使用 \
进行转义,但没有成功。
如何让我的代码带 $
符号?
这些选项在 bash 中对我有用:
$ python test.py 'Sample$how'
Sample$how
$ python test.py Sample$how
Sample$how
$ python test.py "Sample$how"
Sample$how
扩展@vds 对问题的评论:
我打赌你使用的是 Powershell(?)
在 Powershell 中,$how
将扩展为(可能不存在的)变量的值 how
:
Python(或任何其他可执行文件)甚至看不到美元符号。
在变量周围添加单引号修复了问题:
python test.py 'Sample$how'
这是我的代码
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("echo")
args = parser.parse_args()
print args.echo
当我尝试从命令行使用 $
传递文本时,它没有被接受。我试图通过在 $
符号之前添加 \
来转义特殊字符,但仍然没有成功。这就是我 运行 代码
python test.py Sample$how
Sample
我在 windows 上,我已经厌倦了使用 \
进行转义,但没有成功。
如何让我的代码带 $
符号?
这些选项在 bash 中对我有用:
$ python test.py 'Sample$how'
Sample$how
$ python test.py Sample$how
Sample$how
$ python test.py "Sample$how"
Sample$how
扩展@vds 对问题的评论:
我打赌你使用的是 Powershell(?)
在 Powershell 中,$how
将扩展为(可能不存在的)变量的值 how
:
Python(或任何其他可执行文件)甚至看不到美元符号。
在变量周围添加单引号修复了问题:
python test.py 'Sample$how'