python 命令行参数

python command line argument

我试图像这样传递一个命令行参数,因为实际的字符串前后包含一个 # 符号

python3 test.py #fdfdf#

这是我收到的错误消息

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    print(sys.argv[1])
IndexError: list index out of range

如何将开头和结尾包含 # 符号的字符串作为命令行参数传递?

更新: OS: Ubuntu 20.04

您可以尝试其中一种,看看哪一种有效:

python3 test.py "#fdfdf#"python3 test.py \#fdfdf\#