0

I am new to python and would like to give the arguments to a script as in-line arguments after the script name.

For example: given the script

mypython_script.py

I would like to launch it from terminal in the following way:

python3.4 mypython_script.py argument_1=5.0, argument_2=12.3, nome_file='out_put.dat'

I am able to read/print into terminal via the following command:

print ('Input Argument_1')
string_input= input()
Argument_1=float(string_input)
print('Argument_1 %f ' % Argument_1)

print ('Input Argument_2')
string_input= input()
Argument_2=float(string_input)
print('Argument_2 %f ' % Argument_2)

print ('Input nome_file')
nome_file= input()
print('nome_file %s ' % nomefile)

But in order to do this I have to interact with the program, my question is: how can I give to the script all the arguments in the line in which I execute it from shell?

Chaos
  • 199
  • 1
  • 13
  • possible duplicate of [Command Line Arguments In Python](http://stackoverflow.com/questions/1009860/command-line-arguments-in-python) – Oliver W. Nov 29 '14 at 17:07

2 Answers2

3

Check out the argparse tutorial for information on how to use the argparse module. It's an easy-to-use yet powerful module for interacting with command-line arguments, setting up help messages, formatting printouts, and more.

MattDMo
  • 100,794
  • 21
  • 241
  • 231
1

You have to use sys.argv to retrive parameter after scripts

sys.argv[0] will give you first argument.

Please use different argument as python script_name.py arg1 arg2 arg3 arg4

If you have to use unix type argument syntext like python script arg1=val1 arg2=val2 then user argparser

Nilesh
  • 20,521
  • 16
  • 92
  • 148