Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63528
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!gordon |
|---|---|
| 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 | Wed, 8 Jan 2014 22:53:24 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 35 |
| Message-ID | <lakkt4$1hj$1@reader1.panix.com> (permalink) |
| References | <bc99af4e-8031-477c-877f-a5460f8a09ab@googlegroups.com> |
| NNTP-Posting-Host | panix3.panix.com |
| X-Trace | reader1.panix.com 1389221604 1587 166.84.1.3 (8 Jan 2014 22:53:24 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Wed, 8 Jan 2014 22:53:24 +0000 (UTC) |
| User-Agent | nn/6.7.3 |
| Xref | csiph.com comp.lang.python:63528 |
Show key headers only | View raw
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