Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80507
| From | "Clayton Kirkwood" <crk@godblessthe.us> |
|---|---|
| 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> |
| Subject | RE: Python script that does batch find and replace in txt files |
| Date | 2014-11-09 15:03 -0800 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15649.1415693661.18130.python-list@python.org> (permalink) |
>-----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
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