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 7578529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:27:13+00:00 2026-05-30T17:27:13+00:00

I am learning from code, and I am get confused by one of its

  • 0

I am learning from code, and I am get confused by one of its lines which is:

things = [float(arg) for arg in sys.argv[1:]]
Omega_a, Omega_b, Delta_a, Delta_b, \
init_pop_a, init_pop_b, tstep, tfinal = things

I have searched online and tried to understand what sys.arg means, and here is my understanding:

So sys.argv[0] is the file name, and sys.argv[1:] is the rest of the parameters which should given by users. I am not sure am I understood it right, and if it is, then I don’t understand why cant it be like:

Omega_a = input() 
Omega_b = input()
etc...

What’s the difference between these two ways of giving parameters?

Also, if I run the code (press F5), the Python shell give me an error like:

Traceback (most recent call last):

File "C:\Users\testcode.py", line 55, in <module>
init_pop_a, init_pop_b, tstep, tfinal = things
ValueError: need more than 0 values to unpack

I wasn’t even given a chance to give parameters (sys.argv[1:]) before it gave me an error. So I searched online. It looks like I need to run this code in cmd which confused me more, why should it and how should I put into cmd in order to run it?

  • 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-05-30T17:27:15+00:00Added an answer on May 30, 2026 at 5:27 pm

    The difference is, that sys.argv (command line) parameters are given before the program is running (while starting it):

    python testcode.py arg1 arg2 arg3 arg4 and so on ...
    

    This would result in your variables being:

    Omega_a = 'arg1'
    Omega_b = 'arg2'
    Delta_a = 'arg3'
    Delta_b = 'arg4'
    init_pop_a = 'and'
    init_pop_b = 'so'
    tstep = 'on'
    tfinal = '...'
    

    While the input()s are given when the program is running.

    As you do not start the program with parameters it gives you the error,
    because there are not enough (exactly 0) parameters to be unpacked into the variables.

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

Sidebar

Related Questions

This is a code snippet from O'Reilly Learning Opencv, cvNamedWindow(Example3, CV_WINDOW_AUTOSIZE); g_capture = cvCreateFileCapture(argv[1]);
I am new to AS3. When learning AS3, I get the below code from
Here's the code from sys import argv script,from_file, to_file = argv open(to_file,'w').write(open(from_file).read()) I'm new
in the book i'm learning from i came across this code snippit: while (i
I am learning to use xmlhttprequest/AJAX. In this sample code from w3schools, I do
Learning from my last question , most member names seem to get included in
I am developing program which need to interact with COM ports. By learning from
I have just started learning ruby reading from different resources. One of them is
Here is my following tutorial code from Learning PHP MYSQL and Javascript by OReilly.
I am learning Nhibernate 3.0. In one of the sample code examples, it creates

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.