replacing words in HTML file

Cameron Simpson cs at zip.com.au
Fri Apr 30 07:37:21 CEST 2010


On 30Apr2010 07:15, Stefan Behnel <stefan_ml at 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 at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

[I]n the current environment, it's really hard to ascribe to stupidity
what can be adequately explained by malice. - Jordin Kare



More information about the Python-list mailing list