我得到一个类型错误,我的类在其函数dl()中使用self
import urllib
import httplib
import os.path
###SAI22 Library###
def exists(site):
conn = httplib.HTTPConnection(site)
conn.request("HEAD",site)
response = conn.getresponse()
conn.close()
return response.status == 200
class sai_download:
def dl(self,_dir,_url,pck):
if pck == True:
if exists(_url) == True:
urllib.urlretrieve(_url,_dir)
if os.path.isfile(_dir) == True:
print "Download successful"
return True
else:
print "Download failed"
return False
else:
print "Url isnt valid"
return False
elif pck == False:
if exists(_url) == True:
urllib.urlretrieve(_url,_dir)
return True
if os.path.isfile(_dir) == True:
return True
else:
return False
else:
return …Run Code Online (Sandbox Code Playgroud)