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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:27:21+00:00 2026-06-15T11:27:21+00:00

I am reading Learn Python the Hard Way and was confused by the script

  • 0

I am reading “Learn Python the Hard Way” and was confused by the “script” part of the second line.

from sys import argv
script, filename = argv

From what I understand, the second line says: script and filename comprise argv.
I tried running my code without the “script” part and it worked just fine. I’m not sure what the purpose of it is.

  • 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-15T11:27:22+00:00Added an answer on June 15, 2026 at 11:27 am

    Generally, the first argument to a command-line executable is the script name, and the rest are the expected arguments.

    Here, argv is a list that is expected to contain two values: the script name and an argument. Using Python’s unpacking notation, you can write

    script = argv[0]
    filename = argv[1]
    

    as

    script, filename = argv
    

    while also throwing errors if there are an unexpected number of arguments (like one or three). This can be a good idea, depending on one’s code, because it also ensures that there are no unexpected arguments.

    However, the following code will not result in filename actually containing the filename:

    filename = argv
    

    This is because filename is now the argument list. To illustrate:

    script, filename = argv
    print("Script:", script)  # Prints script name
    print("Filename:", filename)  # Prints the first argument
    
    filename = argv
    print("Filname:", filename)  # Prints something like ["my-script.py", "my-file.txt"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading Learn Python The Hard Way and I am really curious what
I have just started reading learn python the hard way and I have a
I'm reading Zed Shaw's Learn Python The Hard Way. I'm up to exercise 17
I have started to learn about python and is currently reading through a script
I am working my way through Learn Python the Hard Way and am stuck
I've been teaching myself Python through the book Learn Python The Hard Way (2nd
I am starting to learn AspectJ. From reading tutorials, I know that I can
Am trying to learn Python the Atlantic way and am stuck on Project Euler
After I learned about reading unicode files in Python 3.0 web script, now it's
I want to learn multiprocessing in python. I started reading http://www.doughellmann.com/PyMOTW/multiprocessing/basics.html and I am

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.