0

I have written simple function to cut lines in txt file, takes 3 arguments :

cut(inicial_line, final_line, file)

now how do i put inicial_line and final_line to -c option to execute it for example:

$ python cut.py -c 5 8 f.txt

and it print file text from 5th to 8th line

1 Answers1

0

i found solution

__name__=='__main__':
        import argparse
        import sys
        pars = argparse.ArgumentParser()
        pars.add_argument('-n', nargs=2, type=int)
        args=pars.parse_args(sys.argv[1:4])
        print cut(args.n[0], args.n[1], sys.argv[4])

main problem was args=pars.parse_args(sys.argv[1:4])

i didnt know that args=pars.parse_args() is the same as args=pars.parse_args(sys.argv[1:])