python - 我可以从命令行将 "\t"传递给 python 吗?

标签 python command-line

<分区>

Possible Duplicate:
Passing meta-characters to Python as arguments from command line

我想从命令行向 python 脚本传递一个参数,以指定我的输入文件的分隔符。 (例如 ",""\t")。为了灵活起见,我想直接在命令行上指定它,而不是将此参数的选项编码到脚本中。

例如

pythonscript.py --in_delimiter "\t" --in_file input.txt

在 python 接收反斜杠之前,我似乎遇到了解释反斜杠的问题。我试图通过添加额外的反斜杠来避免这种情况,但无法使其正常工作。

我的问题:是否可以从命令行传递类似“\t”的内容,或者我是否必须使用我在脚本中解释的代码(例如 c = ", "t= "\t" 等)。

感谢您的帮助。

最佳答案

你是用 Bash 做的吗?如果是这样,请尝试:

pythonscript.py --in_delimiter $'\t' --in_file input.txt

关于python - 我可以从命令行将 "\t"传递给 python 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14251307/

相关文章:

python - 使用 python 在 win 10 上切换 "night light"功能

python - 在pygame中添加/创建下拉选择框的技巧

c# - 在命令提示符下编译/执行 C# 源文件

ubuntu - 如何使用 S3QL 在 aws s3 中列出对象

python - 创建在执行之间持续存在的内存缓存

python - 仅使用 for 循环遍历文件是一种好的形式吗?

python - Python 3 中 "running a function only once"的变体

javascript - Python Selenium : Click on a radio button

linux - 使用 find 使用随机字符递归重命名文件

regex - 如何在 linux shell 中使用正则表达式从文件中提取 IP 地址?