Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80444
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.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; 'syntax': 0.04; 'subject:Python': 0.06; 'executed': 0.09; 'line:': 0.09; 'subject:files': 0.09; 'subject:script': 0.09; '"_")': 0.16; "']'": 0.16; '.txt': 0.16; 'be:': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'newlines': 0.16; 'received:192.168.1.4': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:txt': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header :User-Agent:1': 0.23; 'error': 0.23; 'header:In-Reply-To:1': 0.27; 'skip:g 30': 0.30; 'code': 0.31; 'subject:that': 0.31; 'txt': 0.31; 'file': 0.32; 'etc': 0.35; 'received:84': 0.35; 'should': 0.36; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'previous': 0.38; 'to:addr:python.org': 0.39; 'break': 0.61; 'invalid': 0.68; 'skip:w 30': 0.69; 'end.': 0.84; 'no:': 0.84; 'subject:find': 0.84; 'syed': 0.84; '|house': 0.84 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=IfMJWAaa c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=aoAcgTy3oA8A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=xM-Kf9Qp6aUxZkcLT2YA:9 a=QEXdDO2ut3YA:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Sun, 09 Nov 2014 21:44:53 +0000 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Python script that does batch find and replace in txt files |
| References | <e9ee1f6f-9397-4dc5-a357-381ebc9b6e57@googlegroups.com> <46769509.90793.1415564600851.JavaMail.yahoo@jws10740.mail.gq1.yahoo.com> <CABHN3iHHHdDg9-yOR6z12o5ujx-iWCa2hn8UCrkzQ98CKjv4xg@mail.gmail.com> <CABHN3iESsRx=RkK3asWvw1Mcp9kdYU14udc3Cx09WtjWNVm5Wg@mail.gmail.com> |
| In-Reply-To | <CABHN3iESsRx=RkK3asWvw1Mcp9kdYU14udc3Cx09WtjWNVm5Wg@mail.gmail.com> |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| 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.15610.1415569683.18130.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1415569683 news.xs4all.nl 2841 [2001:888:2000:d::a6]:50129 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:80444 |
Show key headers only | View raw
On 2014-11-09 21:20, Syed Khalid wrote:
>
> Code after adding path of .txt files :
>
> import glob, codecs, re, os
>
> regex = re.compile(r"Age: |Sex: |House No: ") # etc etc
>
> 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 "Elector'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))
>
>
> I executed code in edit rocket.
>
> Error message :
>
>
> File "EamClean.log", line 12
> with codecs.open(txt + "_out.txt", "wb", encoding="utf-8") as w:
> ^
> SyntaxError: invalid syntax
>
[snip]
The previous line is missing a ']' on the end. It should be:
newlines = [regex.sub("", line).strip().replace("-", "_") for line
in oldlines[i:]]
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