class - Passing arguments for functions while opening python file from terminal in Linux -
i'm trying open python script have through terminal in linux, in format shown below:
$ python file_name.py a,b,c
over here a,b,c variables i'm using in code i've written program. i'm getting input asking user enter input using command var_name = input("enter input a: ")
however want pass value these 3 variables while opening file mentioned in format above . have make use of classes this?
the code wrote :
print"hello!" circle = [] n = input("enter number of elements in circle 'n' :") in range(0,n): circle.append(i) print "the circle being formed : " + str(circle) m = input("enter value of m : ") k = input("enter value of k : ") index = m-1 while (len(circle)>k) : del circle[index] index = index + (m-1) n = n - 1 index = (index)%n print str(circle)
if you're on python 2.7 (which likely) can try argparser
import argparse parser = argparse.argumentparser(description='process integers.') parser.add_argument('integers', metavar='n', type=int, nargs='+', help='an integer accumulator') parser.add_argument('--sum', dest='accumulate', action='store_const', const=sum, default=max, help='sum integers (default: find max)') args = parser.parse_args() print args.accumulate(args.integers)
and run:
$ python prog.py 1 2 3 4 4 $ python prog.py 1 2 3 4 --sum 10
Comments
Post a Comment