如何将&符作为python中的命令行参数的一部分进行处理 [英] How to handle ampersand as part a command line argument in python
问题描述
我在python 2.7中有一个程序,该程序使用argparse
接受命令行参数,但是,如果我尝试输入包含&"号的字符串,则会在该&"号之后丢失字符.
I have a program in python 2.7 which accepts command line parameters using argparse
, however if I try to enter a string containing an ampersand I lose the characters after that ampersand.
例如:
我有一个简单的python程序,用于测试命令行参数的输入,并简单地打印出为单个命令行参数输入的内容.
I have a simple python program just to test the input of command line arguments and simply prints out what was entered for a single command line parameter.
本质上:print args.where
当我使用类似这样的参数运行程序时:
When I run the program with an argument like this:
$ python args.py -a http://www.website.com?optionone=one&numbertwo=two
打印到屏幕上的唯一文本是: http://www.website.com?optionone=one
The only text printed to the screen is: http://www.website.com?optionone=one
使用sys和使用Argv的printIng时,我得到类似的结果
I have similar results when using sys and printIng using Argv
如何获取完整的字符串?
How can I get the full string entered?
推荐答案
这是您的shell的问题.将参数用引号引起来.
This is a problem with your shell. Put the argument in quotes.
这篇关于如何将&符作为python中的命令行参数的一部分进行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!