0

If I have a scripts test.py which contains some arguments. I run this shell

python test.py --a this_a --b this_b

I want to get this string python test.py --a this_a --b this_b in test.py. How can I get this?

Ivaylo Strandjev
  • 69,226
  • 18
  • 123
  • 176
  • Check out this post: https://stackoverflow.com/questions/4117530/sys-argv1-meaning-in-script – warped Jan 04 '22 at 11:31
  • If you wanted the full path to the python executable too, you could use `sys.orig_argv` instead of just `sys.argv` – Adid Jan 04 '22 at 11:33
  • 2
    I’m not so sure this is a duplicate. At any rate, there’s really no portable way of retrieving the original command line, since that is never passed into the process. There might not even *be* a command line, depending on how the process is launched. What exact purpose do you need the command line string for? – Konrad Rudolph Jan 04 '22 at 11:37
  • The duplicate ref is wrong, since `sys.argv` starts with the script name, and doesn't contain the entire command line. – bereal Jan 04 '22 at 11:37
  • 1
    Does this answer your question: [Get all command line arguments in python](https://stackoverflow.com/q/57935592/770830)? – bereal Jan 04 '22 at 11:42
  • @bereal I trust you are aware that you can change the list of duplicates without reopening? – tripleee Jan 04 '22 at 11:47
  • @tripleee I am, but I was not sure that it was what the OP wanted, so I asked. – bereal Jan 04 '22 at 11:50

0 Answers0