Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (1.6k points)

How do I have a Python script that a) can accept user input and how do I make it b) read in arguments if run from the command line?

1 Answer

0 votes
by (25.1k points)

You can get user input using the input method in python 3 and raw_input in python 2 e.g.: 

data = input("Enter your name") # for python 3

data = raw_input("Enter your name") # for python 2

For command line arguments you can use the sys.argv like this:

import sys


Note that sys.argv is a list with the first element as the file name and rest of the elements are arguments passed by the user.

Related questions

0 votes
1 answer
asked Sep 23, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

30.5k questions

32.5k answers


108k users

Browse Categories