0
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

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

4

1 回答 1

2

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

于 2012-07-04T09:35:55.783 回答