Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8402037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:57:03+00:00 2026-06-09T21:57:03+00:00

If using sys.argv would there be any reason to use the *arg or would

  • 0

If using sys.argv would there be any reason to use the *arg or would sys.argv be able to do everything that *arg would?

For instance:

>>>def test(*arg):
>>>    return arg
>>>
>>>print test('hello','salut','hola')
>>>('hello','salut','hola')

When I use sys.argv inside a file called trial.py that I call from the command-line:

import sys
def test(argument):
    return argument

print test(sys.argv[1])


python trial.py 'hello','salut','hola'
hello,salut,hola

Or is argv really geared to receiving just one argument and is it possible for argv to have more than 2 items(argv[0],argv[1])?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:57:05+00:00Added an answer on June 9, 2026 at 9:57 pm

    sys.argv is a list containing all the arguments your python script was invoked with on the command line, with the script itself considered to be “argument 0”.

    It’s an ordinary variable, same as any other variable that happens to contain a list. So there is no “choice” between sys.argv and *arg. *arg is syntax used for unpacking a list (or other sequence) to pass as multiple arguments to a call. You can use this syntax when passing sys.argv, as you can with any other variable containing a list. Or you can leave off the * and pass the whole list as one argument. Again, whether the list happens to be sys.argv is irrelevant to what happens.

    I think the source of your confusion is that the shell from which you’re invoking your python script doesn’t consider multiple arguments to be separated the same way Python does. In Python, you separate multiple arguments with commas, so 'hello','salut','hola' would be 3 arguments (although it would be more usual style to put spaces after the commas).

    In most shells OTOH, arguments are separated by whitespace. 'hello','salut','hola' does not contain any white space, so it’s just one argument. So it shows up in the Python list in sys.argv as one item. Nothing magic has happened to concatenate multiple arguments into one for you; it’s just that there only ever was one argument. The way to get the Python-level sys.argv to have 3 items would be to invoke your script like this:

    python trial.py 'hello' 'salut' 'hola'
    

    It also looks like you’re using quotes in the shell command line the way you would in Python. In most shells, you don’t always need to quote strings because everything is a string. Instead, quotes are used to tell the shell that a string containing whitespace is actually one argument with whitespace in it, rather than multiple arguments, or to disable certain special processing that shells do by default everywhere.

    In Python 'hello' is necessary to make the string “hello”, so that Python doesn’t try to read it as a variable hello. But in shells, 'hello' and hello are both identical, and just mean the string “hello”. But it would also be possible to write he'll'o with only a part of the string quoted. This just changes how the shell processes whitespace and other special characters inside the quotes, but still results in the same string “hello”. This is why the shell is interpreting your form 'hello','salut','hola' as the string “hello,salut,hola”. There’s no whitespace outside the quotes, so the 3 words doesn’t get treated as separate arguments, and after doing their job of telling the shell how to process special characters the quotes just disappear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I notice that when using sys.getsizeof() to check the size of list and dictionary,
I would like use argparse to parse the arguments that it knows and then
I'm using Python to call bash to execute another bash script: begin = int(sys.argv[1])
I know how to query the cpu type in C code using the sys/systemcfg.h
I'm trying to generate an executable. the packages I am using are import sys
I'm using Client Side templates in my JavaScript. $create(Sys.UI.DataView, { data: data }, null,
I'm using mysql-python . Here's my settings.py import os, sys abspath = lambda *p:
#include <ctime> #include <cstdio> #include <sys/time.h> #include <iostream> using namespace std; int main() {
Hello I have test's using unittest. I have a test suite and I am
I have a huge CSV file I would like to process using Hadoop MapReduce

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.