[英]Can I pass Python command line arguments which include '#'? (Without escaping?)
I'm trying to write a Python script which grabs command line arguments and uses them as search terms with the twitter api. 我正在尝试编写一个Python脚本来抓取命令行参数,并将它们用作twitter api的搜索词。 I'd like to allow others using the script to insert a hashtag as a search term without having to escape the hash, or pound sign. 我想允许其他人使用脚本将主题标签作为搜索词插入,而不必转义哈希或井号。
Here's a two line script illustrating my issue: 这是一个说明我的问题的两行脚本:
import sys
print "\n".join(sys.argv[1:])
Example usage: 用法示例:
$ python example.py one two \#three #four five
one
two
#three
$
Is there a way I could get in arguments which include a hash without forcing the user of the script to escape them? 有没有一种方法可以获得包含哈希的参数而不强制脚本的用户逃脱它们?
你可以把它们放在引号中。
python example.py one two "#three" "#four" five
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.