syntax error: invalid syntax 问题

bolv6666 2019-09-22 09:48:29
各位大神,小弟初学python,下载数据的时候,运行.py文件总是出现这个错误,

download.py文件已经是在s:\Python_FNL文件夹下,且没有在python环境中,是在cmd环境中。download.py文件如下:
:: python script to download selected files from rda.ucar.edu
::
import sys
import os
import urllib2
import cookielib
::
if (len(sys.argv) != 2):
print "usage: "+sys.argv[0]+" [-q] password_on_RDA_webserver"
print "-q suppresses the progress message for each file that is downloaded"
sys.exit(1)
::
passwd_idx=1
verbose=True
if (len(sys.argv) == 3 and sys.argv[1] == "-q"):
passwd_idx=2
verbose=False
::
cj=cookielib.MozillaCookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
::
:: check for existing cookies file and authenticate if necessary
do_authentication=False
if (os.path.isfile("auth.rda.ucar.edu")):
cj.load("auth.rda.ucar.edu",False,True)
for cookie in cj:
if (cookie.name == "sess" and cookie.is_expired()):
do_authentication=True
else:
do_authentication=True
if (do_authentication):
login=opener.open("https://rda.ucar.edu/cgi-bin/login","email=scienceliaocheng@sina.com&password="+sys.argv[1]+"&action=login")
::
:: save the authentication cookies for future downloads
:: NOTE! - cookies are saved for future sessions because overly-frequent authentication to our server can cause your data access to be blocked
cj.clear_session_cookies()
cj.save("auth.rda.ucar.edu",True,True)
::
:: download the data file(s)
listoffiles=["grib2/2017/2017.06/fnl_20170602_00_00.grib2","grib2/2017/2017.06/fnl_20170602_06_00.grib2","grib2/2017/2017.06/fnl_20170602_12_00.grib2"]
for file in listoffiles:
idx=file.rfind("/")
if (idx > 0):
ofile=file[idx+1:]
else:
ofile=file
if (verbose):
sys.stdout.write("downloading "+ofile+"...")
sys.stdout.flush()
infile=opener.open("http://rda.ucar.edu/data/ds083.2/"+file)
outfile=open(ofile,"wb")
outfile.write(infile.read())
outfile.close()
if (verbose):
sys.stdout.write("done.\n")

请问这是怎么回事呢
...全文
863 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
一笑程序猴 2019-09-23
  • 打赏
  • 举报
回复
应该把所有的::换成#
  • 打赏
  • 举报
回复
把::换成 #
铖邑 2019-09-22
  • 打赏
  • 举报
回复
这个“::”应该是注释符“#”,你这样把注释部分全都当作代码执行了
bolv6666 2019-09-22
  • 打赏
  • 举报
回复
忘了说明,python 版本号3.7.4

37,742

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧