replacing words in HTML file

Stefan Behnel stefan_ml at behnel.de
Fri Apr 30 07:15:39 CEST 2010


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.

Stefan




More information about the Python-list mailing list