简体   繁体   English

我可以传递包含'#'的Python命令行参数吗? (没有逃脱?)

[英]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.

相关问题 我可以将命令行参数传递给Abaqus python吗? - Can I pass command-line arguments to Abaqus python? 将命令行参数传递给没有脚本文件的python解释器 - pass command line arguments to python interpreter without a script file Python - 没有 [''] 的命令行参数 - Python - Command line arguments without [ ' ' ] 有没有一种方法可以在 python 中传递 0 命令行 arguments 并且如果传递了特定参数则具有相同的结果? - Is there a way that I can pass 0 command line arguments in python and have the same result if a particular argument is passed? 如何在Python中将“开始日期”和“结束日期”作为命令行参数传递 - How can I pass “start date” and “end date” as command line arguments in Python 如何在python脚本功能内部的sql查询中传递多个命令行参数或系统参数? - How to pass multiple command line arguments or system arguments in sql query which is inside the function of python script? Python:将通用字典作为命令行参数传递 - Python: Pass a generic dictionary as a command line arguments 如何使用 vanila python 在命令行上获取 arguments? - How can I get the arguments on a command-line with vanila python? 如何在Python中处理命令行参数? - How can I process command line arguments in Python? 如何指定某些命令行参数在 Python 中是必需的? - How can I specify that some command line arguments are mandatory in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM