SyntaxError:无效语法href ='http://maps.google.com'+ href

时间:2012-07-04 09:34:45

标签: python compiler-errors

def download_if_dne(href, filename):
    if os.path.isfile(filename):
#        print 'already downloaded:', href
        return False
    else:
        if not href.startswith('http://'
            href = 'http://maps.google.com' + href
            print 'Fixed url :', href
        try:
            print 'downloading:', href
            oa = openanything.fetch(href)
            if oa['status']==200:
                file = open( filename, 'w' )
                file.write( oa['data'] )
                file.close()
            return True
        except KeyboardInterrupt:
            raise
        except:
            print '\tdownload failed -', sys.exc_info()[0]
            return False

此代码是对软件ogmaps的编辑 http://code.google.com/p/ogmaps/issues/detail?id=1

错误讯息:

  File "ogmaps.py", line 36
    href = 'http://maps.google.com' + href
       ^
SyntaxError: invalid syntax

我不是蟒蛇人,无法弄清楚错误的原因。

1 个答案:

答案 0 :(得分:2)

if not href.startswith('http://'应为if not href.startswith('http://'):