0

I have 2 plot it's work using my data analysis. I have some options -x, -y, -e — these work. Now I am trying to add to arguments:

--first 
--second 

When we execute the file.py --first, it should show the first plot and exit; if we choose --second, the second plot and exit. I am trying to solve that but I could not find the solution.

def Plot_XvsY(x,y):
    plot(x1,y1,'bx-',ms=5)
    plot(x2,y2,'r+-',ms=3)
    show()


def plot_wVSs(w,s):
    plot(w,s,'bx-',ms=5)
    plot(w,s,'r+-',ms=3)
    show()


parser.add_argument('-c', '--first', action='store_true', default=False)

Note: it's just part of the code to give you an idea about the issue.

And what if i want to :

for exemple if i have x.py and y.py and arg_argument.py and when i put ./x.py -h or ./y.py -h they have the same argument , i want to use some argument in x ONLY and the others on Y ONLY and mybe some arguments in X AND Y

hpaulj
  • 221,503
  • 14
  • 230
  • 353
user2504287
  • 47
  • 1
  • 1
  • 5

1 Answers1

0

A parser along this line should behave as you describe. (this is just a sketch, and not tested).

parser = argparse.ArgumentParser()
....
parser.add_argument('--first', action='store_true')
parser.add_argument('--second', action='store_true')
args = parser.parse_args()

if args.first:
    <<call the plt1 function>>
elif args.second:
    <<call the other>>
else:
    <<do something else>>

plugins pattern + sub command Includes module import xtatements

Community
  • 1
  • 1
hpaulj
  • 221,503
  • 14
  • 230
  • 353
  • But the module for function is not the module whit Arguments ? how can i reslove that – user2504287 May 03 '16 at 09:26
  • for exemple if i have x.py and y.py and arg_argument.py and when i put ./x.py -h or ./y.py -h they have the same argument , i want to use some argument in x ONLY and the others on Y ONLY and mybe some arguments in X AND Y – user2504287 May 03 '16 at 14:17
  • I can't figure out what you want. – hpaulj May 03 '16 at 16:09
  • file of args (-i -k -o -p -m) , i want x.py to have just -i -k -o to use when --help and Y.py just -o -p -m , Fixing the utilisation of args – user2504287 May 04 '16 at 09:00