- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do we access command line arguments in Python?
Command line is the place where executable commands are given to operating system. A Python script can be executed by writing its name in front of python executable in the command line.
If you want some data elements to be passed to Python script for its processing, these elements are written as space delimited values in continuation to name of script. This list of space delimited values are called command line arguments.
C:\users\acer>python test.py Hello TutorialsPoint
Items separated by space are stored in a special List object called argv. It is defined in sys module of Python distribution.
In above example, the List object would contain:
sys.argv=[‘test.py’, ‘Hello’, ‘TutorialsPoint’]
In the program access these arguments by
import sys print ("first command line argument: ",sys.argv) print ("second command line argument: ",sys.argv)
- Command Line Arguments in Python
- How to add command line arguments in Python?
- Java command line arguments
- Command Line and Variable Arguments in Python?
- Command Line arguments in C#
- Command line arguments in Java
- Command Line arguments in Lua
- Explain Java command line arguments.
- Command Line arguments in Java programming
- Command line arguments in C/C++
- Command line arguments example in C
- How to Parse Command Line Arguments in C++?
- How to do Python math at command line?
- getopt() function in C to parse command line arguments
- How command line arguments are passed in main method in C#?