SyntaxError: 'return' outside function

skip at pobox.com skip at pobox.com
Wed Jan 31 16:49:13 EST 2007


    Melih> Has anyone seen this error before and been able to solve it? I
    Melih> can't seem to find anything that leads to a solution.

Your code is incorrectly indented.  Try:

    def legiturl(self, url):
    # this breaks down the url into 6 components to make sure it's "legit"
        t = urlparse.urlparse(url)

        if t[0] != 'http':
            return ""

        # remove URL fragments, but not URL
        if len(t[5]) > 0:
            url = urlparse.urlunparse((t[0],t[1],t[2],"","",""))
            t = urlparse.urlparse(url)

        # stupid parser sometimes leaves frag in path
        x = find(t[2], '#')
        if x >= 0:
            return ""

instead.  Note also the lack of a return at the end of the function.

Skip



More information about the Python-list mailing list