小编Mao*_*ght的帖子

python TypeError:dl()只需4个参数(给定3个)

我得到一个类型错误,我的类在其函数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)

python class urllib

1
推荐指数
1
解决办法
2549
查看次数

标签 统计

class ×1

python ×1

urllib ×1