How to handle ampersand as part a command line argument in python

后端 未结 2 1046
青春惊慌失措
青春惊慌失措 2020-12-20 23:21

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 chara

相关标签:
2条回答
  • 2020-12-20 23:39

    This is a problem with your shell. Put the argument in quotes.

    0 讨论(0)
  • 2020-12-20 23:53

    You can escape the ampersand with a backslash:

    $ python args.py -a http://www.website.com?optionone=one\&numbertwo=two
    
    0 讨论(0)
提交回复
热议问题