Really appreciate all the all the different answers and learning tips!
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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'
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
> 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
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
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,
<[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
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
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)),
>
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)),
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
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
14 matches
Mail list logo