python command line argument

Viewed 49

I am trying to pass a command line argument like this because the actual string contains a # symbol before and after it

python3 test.py #fdfdf#

This is the error message I am getting

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

How can I pass a string which contains a # symbol in the beginning and the end as a command line argument?

Update: OS: Ubuntu 20.04

1 Answers

You can try one of these and see which one works:

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

Related