Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.048 X-Spam-Evidence: '*H*': 0.90; '*S*': 0.00; 'skip:[ 20': 0.04; 'syntax': 0.04; 'subject:Python': 0.06; 'line:': 0.09; 'subject:files': 0.09; 'subject:script': 0.09; 'python': 0.11; '"_")': 0.16; '1:08': 0.16; '>in': 0.16; 'email addr:python.org]': 0.16; 'newlines': 0.16; 'script,': 0.16; 'subject:txt': 0.16; 'message-----': 0.19; 'replace': 0.24; 'looks': 0.24; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'skip:g 30': 0.30; 'url:mailman': 0.30; 'subject:that': 0.31; 'txt': 0.31; 'file': 0.32; 'url:python': 0.33; 'etc': 0.35; 'skip:> 10': 0.36; 'url:listinfo': 0.36; 'charset:us-ascii': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.37; 'skip:[ 10': 0.38; 'to:addr:python- list': 0.38; 'files': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'break': 0.61; 'received:173': 0.61; 're:': 0.63; 'email name:python-list': 0.65; 'received:phx3.secureserver.net': 0.65; 'received:prod.phx3.secureserver.net': 0.65; 'header:Reply-To:1': 0.67; 'invalid': 0.68; 'skip:w 30': 0.69; 'reply-to:no real name:2**0': 0.71; 'no:': 0.84; 'subject:find': 0.84; 'syed': 0.84; '|house': 0.84; 'received:173.201': 0.91; 'received:173.201.192': 0.91 From: "Clayton Kirkwood" To: References: <46769509.90793.1415564600851.JavaMail.yahoo@jws10740.mail.gq1.yahoo.com> <76a85d07-fbf2-49a7-866a-c990aa0f85b1@googlegroups.com> In-Reply-To: <76a85d07-fbf2-49a7-866a-c990aa0f85b1@googlegroups.com> Subject: RE: Python script that does batch find and replace in txt files Date: Sun, 9 Nov 2014 15:03:58 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac/8YaqGzv2icxpSQhOZvVGazXoIBAAD5L4g Content-Language: en-us X-Mailman-Approved-At: Tue, 11 Nov 2014 09:14:20 +0100 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: crk@godblessthe.us List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 50 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415693661 news.xs4all.nl 2916 [2001:888:2000:d::a6]:49672 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80507 >-----Original Message----- >From: Python-list [mailto:python-list- >bounces+crk=godblessthe.us@python.org] On Behalf Of Syed Khalid >Sent: Sunday, November 09, 2014 1:08 PM >To: python-list@python.org >Subject: Re: Python script that does batch find and replace in txt files > >My Script, > >I have added > >import glob, codecs, re, os > >regex = re.compile(r"Age: |Sex: |House No: ") # etc etc Script I >executed in EditRocket : > >for txt in glob.glob("/D:/Python/source/*.txt"): > with codecs.open(txt, encoding="utf-8") as f: > oldlines = f.readlines() > for i, line in enumerate(oldlines): > if "Contact's Name:" in line: > break > newlines = [regex.sub("", line).strip().replace("-", "_") for line >in oldlines[i:] > with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w: > w.write(os.linesep.join(newlines)) > To my young eyes, it looks like you are missing a ] at the end of the line before the with. > >Error Message : > > File "EamClean.log", line 12 > with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w: > ^ >SyntaxError: invalid syntax > >Kindly do the needful > > > >-- >https://mail.python.org/mailman/listinfo/python-list