Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12987
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'from:addr:python': 0.09; 'skip:[ 30': 0.09; 'fin.close()': 0.16; 'fin:': 0.16; 'fout': 0.16; 'fout.close()': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'immutable,': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'messy': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply-to:addr:python-list': 0.16; 'result:': 0.16; 'scrub': 0.16; 'subject:Deleting': 0.16; 'wrote:': 0.16; 'file)': 0.18; 'result.': 0.21; 'header:In-Reply- To:1': 0.22; 'changed': 0.24; 'code': 0.25; 'received:84': 0.28; 'error': 0.32; 'list': 0.32; "can't": 0.33; 'to:addr:python-list': 0.33; 'header:User-Agent:1': 0.34; 'file.': 0.34; 'reply- to:addr:python.org': 0.34; 'skip:" 20': 0.35; 'file': 0.36; 'doing': 0.36; 'skip:" 10': 0.36; 'put': 0.37; 'but': 0.37; 'hello,': 0.38; 'subject:: ': 0.39; 'data': 0.39; 'to:addr:python.org': 0.39; 'subject:from': 0.40; 'here': 0.65; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.71; '.replace': 0.84; 'words).': 0.84 |
| X-IronPort-Anti-Spam-Filtered | true |
| X-IronPort-Anti-Spam-Result | AgYIABtraU7Unw4S/2dsb2JhbABCmTOMXoFzeIFGAQEFOEARCwgQCRQCDwkDAgECAQ04EwgBAYdzuFKGbQSLdUmMB4wE |
| Date | Fri, 09 Sep 2011 02:31:23 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Python: Deleting specific words from a file. |
| References | <30f9b718-bb3c-4c92-8a03-0f760c993939@a12g2000yqi.googlegroups.com> |
| In-Reply-To | <30f9b718-bb3c-4c92-8a03-0f760c993939@a12g2000yqi.googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | python-list@python.org |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.888.1315531942.27778.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1315531942 news.xs4all.nl 2465 [2001:888:2000:d::a6]:53783 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:12987 |
Show key headers only | View raw
On 09/09/2011 02:09, papu wrote: > Hello, I have a data file (un-structed messy file) from which I have > to scrub specific list of words (delete words). > > Here is what I am doing but with no result: > > infile = "messy_data_file.txt" > outfile = "cleaned_file.txt" > > delete_list = ["word_1","word_2"....,"word_n"] > new_file = [] > fin=open(infile,"") > fout = open(outfile,"w+") > for line in fin: > for word in delete_list: > line.replace(word, "") > fout.write(line) > fin.close() > fout.close() > > I have put the code above in a file. When I execute it, I dont see the > result file. I am not sure what the error is. Please let me know what > I am doing wrong. The .replace method _returns_ its result. Strings are immutable, they can't be changed in-place.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python: Deleting specific words from a file. papu <prachar@gmail.com> - 2011-09-08 18:09 -0700
Re: Python: Deleting specific words from a file. MRAB <python@mrabarnett.plus.com> - 2011-09-09 02:31 +0100
Re: Python: Deleting specific words from a file. John Gordon <gordon@panix.com> - 2011-09-09 03:16 +0000
Re: Python: Deleting specific words from a file. Terry Reedy <tjreedy@udel.edu> - 2011-09-09 02:04 -0400
Re: Python: Deleting specific words from a file. gry <georgeryoung@gmail.com> - 2011-09-12 12:49 -0700
Re: Python: Deleting specific words from a file. MRAB <python@mrabarnett.plus.com> - 2011-09-12 21:42 +0100
csiph-web