Questions about Python sys.argv

Asked 2 years ago, Updated 2 years ago, 16 views

C:/doti/Mymod>python argv_test.py you need python
['argv_test.py', 'you', 'need', 'python']

Hello. I have a quick question about Python sys grammar.

If you enter it in the cmd window as shown in the top picture in the textbook, the shaded part is added to the value of the sys.argv list Entering the statement and outputting sys.argv does not add the corresponding values.

How do we do that?

If you type Python test.py abc in cmd, the interpreter won't run, so I wonder if it's right to type it like a textbook.

python

2022-09-20 14:42

1 Answers

You have to use sys.argv inside test.py.

It's not like you're running Python separately as you see in the question.

For example, test the contents below.Save as py.

import sys
print(sys.argv)

The test where the above is saved.You can run py with the command line arguments you want.


2022-09-20 14:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.