Python Forum
How to input & output parameters from command line argument
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to input & output parameters from command line argument
#2
for simple input, you can use sys.argv
example:

sysargv.py
import sys

for n, item in enumerate(sys.argv):
    print(sys.argv[n]) 
running python sysargv.py one beta delta hello
Output:
sysargv.py one beta delta hello
Note: sys.argv[0] is the script name.

A better way is to use argparse: https://docs.python.org/3/howto/argparse.html
Reply


Messages In This Thread
RE: How to input & output parameters from command line argument - by Larz60+ - Apr-13-2021, 02:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Reading and storing a line of output from pexpect child eagerissac 1 4,259 Feb-20-2024, 05:51 AM
Last Post: ayoshittu
  Receive Input on Same Line? johnywhy 8 725 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  problem in using input command akbarza 4 1,132 Oct-19-2023, 03:27 PM
Last Post: popejose
  capturing multiline output for number of parameters jss 3 820 Sep-01-2023, 05:42 PM
Last Post: jss
  output provide the filename along with the input file processed. arjunaram 1 942 Apr-13-2023, 08:15 PM
Last Post: menator01
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,094 Jan-16-2023, 07:38 PM
Last Post: Skaperen
Information How to take url in telegram bot user input and put it as an argument in a function? askfriends 0 1,095 Dec-25-2022, 03:00 PM
Last Post: askfriends
  Command line argument issue space issue mg24 5 1,341 Oct-26-2022, 11:05 PM
Last Post: Yoriz
  accept command line argument mg24 5 1,317 Sep-27-2022, 05:58 PM
Last Post: snippsat
  Os command output in variable shows wrong value paulo79 2 1,514 Apr-09-2022, 03:48 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020