Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63529

Re: python copy selected lines from one file to another using argparse or getopt

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'tutorial': 0.03; 'from:addr:yahoo.co.uk': 0.04; 'one?': 0.05; 'modifying': 0.07; 'subject:file': 0.07; 'suppose': 0.07; 'denoted': 0.09; 'file)': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:using': 0.09; 'python': 0.11; 'suggest': 0.14; 'language.': 0.14; '(e.g': 0.16; 'be:': 0.16; 'denote': 0.16; 'excludes': 0.16; 'pypi.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'subject:argparse': 0.16; 'words.': 0.16; 'subject:python': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'command': 0.22; 'input': 0.22; 'header:User- Agent:1': 0.23; 'file.': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'words': 0.29; 'specified': 0.30; 'code': 0.31; 'lines': 0.31; 'exclude': 0.31; 'searches': 0.31; 'txt': 0.31; 'file': 0.32; 'option': 0.32; 'another': 0.32; 'third': 0.33; 'subject:from': 0.34; 'but': 0.35; 'subject:one': 0.36; 'done': 0.36; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'new': 0.61; 'email addr:gmail.com': 0.63; 'our': 0.64; 'containing': 0.69; 'abc': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: python copy selected lines from one file to another using argparse or getopt
Date Wed, 08 Jan 2014 23:03:53 +0000
References <bc99af4e-8031-477c-877f-a5460f8a09ab@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-147-191-18.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
In-Reply-To <bc99af4e-8031-477c-877f-a5460f8a09ab@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5205.1389222258.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1389222258 news.xs4all.nl 2833 [2001:888:2000:d::a6]:35403
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:63529

Show key headers only | View raw


On 08/01/2014 21:51, sagarnildass@gmail.com wrote:
> I am trying to write a program in python which searches for user specified words in a txt file and copies the selected lines containing that word into another file.
>
> Also the user will have an option to exclude any word.
>
> (e.g Suppose the user searches for the word "exception" and want to exclude the word "abc", then the code will only copy the lines which has "exception" in it but not "abc").
>
> Now all the work will be done from the command prompt.
>
> The input would be:
>
> file.py test.txt(input file) test_mod.txt(output file) -e abc(exclude word denoted by -e)-s exception(search word denoted by -s)
> Now the user will have an option to enter multiple exclude words and multiple search words.
>
> Now so far I have achieved that the input format is:
>
> file.py test.txt test_mod.txt abc exception".
> This excludes the word "abc" and search for "exception".
>
> 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.
> Please can somebody help me by modifying my code or write a new one?
>

If you can use third party modules I suggest you look at docopt, it's 
available on pypi.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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