Prev: Need help in python plug-in development
Next: wxPython problem: Can't assign size of plot.PlotCanvas
From: Cameron Simpson on 30 Apr 2010 01:37
On 30Apr2010 07:15, Stefan Behnel <stefan_ml(a)behnel.de> wrote:
| Cameron Simpson, 30.04.2010 00:47:
| >Here's a function from a script I wrote to bulk edit a web site. I was
| >replacing OBJECT and EMBED nodes with modern versions:
| > def recurse(node):
| > global didmod
| > [...]
| > didmod=True
| > continue
| > recurse(O)
| >The calling end looks like this:
| > SOUP = BeautifulSoup(srctext)
| > didmod = False # icky global set by recurse()
| > recurse(SOUP)
| > if didmod:
| > srctext = str(SOUP)
| >If didmod becomes True we recompute srctext and resave the file (or save it
| >to a copy).
| You should rethink your naming in the above code and remove the need
| for a global variable.
Absolutely. It was a quick hack, not something I was intending anyone
else to use.
Cameron Simpson <cs(a)zip.com.au> DoD#743
[I]n the current environment, it's really hard to ascribe to stupidity
what can be adequately explained by malice. - Jordin Kare
From: Walter Dörwald on 30 Apr 2010 05:27
On 28.04.10 15:02, james_027 wrote:
> Any idea how I can replace words in a html file? Meaning only the
> remain untouch.
You could try XIST (http://www.livinglogic.de/Python/xist/):
from ll.xist import xsc, parsers
def p2p(node, converter):
if isinstance(node, xsc.Text):
node = node.replace("Python", "Parrot")
node = node.replace("python", "parrot")
node = parsers.parseurl("http://www.python.org/", tidy=True)
node = node.mapped(p2p)
Hope that helps!