Re: Search & Replace

2006-10-27 Thread DataSmash
Really appreciate all the all the different answers and learning tips! -- http://mail.python.org/mailman/listinfo/python-list

Re: Search & Replace

2006-10-27 Thread Frederic Rentsch
DataSmash wrote: > Hello, > I need to search and replace 4 words in a text file. > Below is my attempt at it, but this code appends > a copy of the text file within itself 4 times. > Can someone help me out. > Thanks! > > # Search & Replace > file = open("text.txt", "r") > text = file.read() > file

Re: Search & Replace

2006-10-26 Thread Paddy
DataSmash wrote: > Hello, > I need to search and replace 4 words in a text file. > Below is my attempt at it, but this code appends > a copy of the text file within itself 4 times. > Can someone help me out. > Thanks! > > # Search & Replace > file = open("text.txt", "r") > text = file.read() > fil

Re: Search & Replace

2006-10-26 Thread Bruno Desthuilliers
DataSmash a écrit : > Hello, > I need to search and replace 4 words in a text file. > Below is my attempt at it, but this code appends > a copy of the text file within itself 4 times. > Can someone help me out. > Thanks! > > # Search & Replace > file = open("text.txt", "r") NB : avoid using 'file'

Re: Search & Replace

2006-10-26 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, DataSmash wrote: > I need to search and replace 4 words in a text file. > Below is my attempt at it, but this code appends > a copy of the text file within itself 4 times. Because you `write()` the whole text four times to the file. Make the 4 replacements first and rebin

Re: Search & Replace

2006-10-26 Thread Tim Chase
> Below is my attempt at it, but this code appends > a copy of the text file within itself 4 times. > Can someone help me out. [snip] > file = open("text.txt", "w") > file.write(text.replace("Left_RefAddr", "FromLeft")) > file.write(text.replace("Left_NonRefAddr", "ToLeft")) > file.write(text.repla

Re: Search & Replace with RegEx

2005-07-12 Thread [EMAIL PROTECTED]
thanks for the comments + help. i think i got it working, although it's not pretty: ## import os import re theRegEx = '.*abs:.*\.*.' p = re.compile(theRegEx, re.IGNORECASE) fileToSearch = 'compreg.dat' print "File to perform search-and-replace on: " + fileToSea

Re: Search & Replace with RegEx

2005-07-12 Thread Thomas Guettler
Am Tue, 12 Jul 2005 01:11:44 -0700 schrieb [EMAIL PROTECTED]: > Hi Pythonistas, > > Here's my problem: I'm using a version of MOOX Firefox > (http://moox.ws/tech/mozilla/) that's been modified to run completely > from a USB Stick. It works fine, except when I install or uninstall an > extension,

Re: Search & Replace with RegEx

2005-07-12 Thread George Sakkis
<[EMAIL PROTECTED]> wrote: [snipped] > For example, after installing a new extension, I change in compreg.dat > > lines such as: > > abs:J:\Firefox\Firefox_Data\Profiles\default.uyw\extensions\{0538E3E3-7E9B-4d49-8831-A227C80A7AD3}\components\nsForecastfox.js,18590 > abs:J:\Firefox\Firefo

Re: search/replace in Python (solved)

2005-05-28 Thread Leif K-Brooks
Vamsee Krishna Gomatam wrote: > text = re.sub( "([^<]*)", r' href="http://www.google.com/search?q=\1";>\1', text ) But see what happens when text contains spaces, or quotes, or ampersands, or... -- http://mail.python.org/mailman/listinfo/python-list

Re: search/replace in Python (solved)

2005-05-28 Thread Vamsee Krishna Gomatam
Leif K-Brooks wrote: > Oliver Andrich wrote: > > > For real-world use you'll want to URL encode and entityify the text: > > import cgi > import urllib > > def google_link(text): > text = text.group(1) > return '%s' % (cgi.escape(urllib.quote(text)), >

Re: search/replace in Python

2005-05-28 Thread Leif K-Brooks
Oliver Andrich wrote: > re.sub(r"(.*)",r" href=http://www.google.com/search?q=\1>\1", text) For real-world use you'll want to URL encode and entityify the text: import cgi import urllib def google_link(text): text = text.group(1) return '%s' % (cgi.escape(urllib.quote(text)),

Re: search/replace in Python

2005-05-28 Thread John Machin
Vamsee Krishna Gomatam wrote: > Hello, > I'm having some problems understanding Regexps in Python. I want > to replace "PHRASE" with > "http://www.google.com/search?q=PHRASE>PHRASE" in a block of > text. How can I achieve this in Python? Sorry for the naive question but > the documentation is

Re: search/replace in Python

2005-05-27 Thread Oliver Andrich
Hi, 2005/5/28, Vamsee Krishna Gomatam <[EMAIL PROTECTED]>: > Hello, > I'm having some problems understanding Regexps in Python. I want > to replace "PHRASE" with > "http://www.google.com/search?q=PHRASE>PHRASE" in a block of > text. How can I achieve this in Python? Sorry for the naive que