Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63528
| From | John Gordon <gordon@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: python copy selected lines from one file to another using argparse or getopt |
| Date | 2014-01-08 22:53 +0000 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <lakkt4$1hj$1@reader1.panix.com> (permalink) |
| References | <bc99af4e-8031-477c-877f-a5460f8a09ab@googlegroups.com> |
In <bc99af4e-8031-477c-877f-a5460f8a09ab@googlegroups.com> sagarnildass@gmail.com writes:
> But I don't know how to:
> Include multiple search word and exclude words
> How to denote them by -e and -s. I have seen the argparse and the getopt
> tutorial. But there's no tutorial on this specific topic.
This should help you get started:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-search', '-s', help='a word to search',
action='append', required=True)
parser.add_argument('-exclude', '-e', help='a word to exclude from search',
action='append')
parser.add_argument('input_file')
parser.add_argument('output_file')
args = parser.parse_args()
Assuming the user provided correct arguments, the args object will have
these attributes:
args.search - a list of words to search for.
args.exclude - a list of words to exclude. Can be None.
args.input_file - the input file name.
args.output_file - the output file name.
--
John Gordon Imagine what it must be like for a real medical doctor to
gordon@panix.com watch 'House', or a real serial killer to watch 'Dexter'.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
python copy selected lines from one file to another using argparse or getopt sagarnildass@gmail.com - 2014-01-08 13:51 -0800 Re: python copy selected lines from one file to another using argparse or getopt John Gordon <gordon@panix.com> - 2014-01-08 22:53 +0000 Re: python copy selected lines from one file to another using argparse or getopt Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-08 23:03 +0000 Re: python copy selected lines from one file to another using argparse or getopt Dave Angel <davea@davea.name> - 2014-01-08 18:57 -0500
csiph-web