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


Groups > comp.lang.python > #80507

RE: Python script that does batch find and replace in txt files

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 <crk@godblessthe.us>
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" <crk@godblessthe.us>
To <python-list@python.org>
References <e9ee1f6f-9397-4dc5-a357-381ebc9b6e57@googlegroups.com> <46769509.90793.1415564600851.JavaMail.yahoo@jws10740.mail.gq1.yahoo.com> <mailman.15608.1415566358.18130.python-list@python.org> <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 <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.15649.1415693661.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw



>-----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


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


Thread

Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-09 11:58 -0800
  Re: Python script that does batch find and replace in txt files Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-09 20:17 +0000
  Re: Python script that does batch find and replace in txt files Albert-Jan Roskam <fomcl@yahoo.com> - 2014-11-09 20:23 +0000
  Re: Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-10 02:22 +0530
    Re: Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-09 13:08 -0800
      RE: Python script that does batch find and replace in txt files "Clayton Kirkwood" <crk@godblessthe.us> - 2014-11-09 15:03 -0800
  Re: Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-10 02:50 +0530
  Re: Python script that does batch find and replace in txt files MRAB <python@mrabarnett.plus.com> - 2014-11-09 21:44 +0000
  Re: Python script that does batch find and replace in txt files Syed Khalid <khalidness@gmail.com> - 2014-11-10 03:21 +0530
  Re: Python script that does batch find and replace in txt files Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-11 20:04 +0000

csiph-web