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

4
  • 1
    import sys; print(sys.argv) should get you started... Commented Jun 15, 2017 at 17:33
  • There's information on using command-line arguments in Python in this question. Which version of Python are you using? Commented Jun 15, 2017 at 17:33
  • 1
    Take a look at the argparse module: docs Commented Jun 15, 2017 at 17:34
  • 1
    Im using python 2.7 Commented Jun 15, 2017 at 18:07

1 Answer 1

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:])

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.