繁体   English   中英

TypeError:function()最多接受6个参数(给定7个)

[英]TypeError: function() takes at most 6 arguments (7 given)

据我所知,我只给我的函数6个参数,而不是根据抛出的错误给出7个参数:

mymap.addpoint(float(x[i][7][0]),float(x[i][7][1]), "#0000FF",None,title,str(x[i][0]))
TypeError: addpoint() takes at most 6 arguments (7 given)

有人可以帮忙吗? 代码如下:

def plotjobs(x,y): #plots the latitude and longitudes of a job on a map (x would be the job dictionary, y is used to differentiate the filename)
    mymap = pygmapsedit.maps(53.644638, -2.526855, 6)
    for i in x:
        title = "<img style = 'float: left' src='some.gif'><img style = 'float: left' src='someother.gif'><div style = 'float: right; width: 200px'><p><b>Route No.:</b> "+str(x[i][0])+"</p><p><b>Postcode:</b> "+str(x[i][1])+"</p><p><b>Visit Date:</b> "+str(x[i][3])+"</p><p><b>Store Name:</b> "+str(x[i][4])+"</p><p><b>Store Address:</b> "+str(x[i][5])+"</p><p><b>Store Telephone No.:</b> "+str(x[i][6])+"</div>"
        mymap.addpoint(float(x[i][7][0]),float(x[i][7][1]), "#0000FF",None,title,None)
    mymap.draw("./"+str(y)+"'s Route.html")

这是我正在使用的模块(pygmaps的编辑版本)中的代码:

def drawpoint(self,f,lat,lon,color,title,windowtext,num):
    f.write('\t\tvar latlng = new google.maps.LatLng(%f, %f);\n'%(lat,lon))
    f.write('\t\tvar img = "http://mapicons.nicolasmollet.com/wp-content/uploads/mapicons/shape-default/color-666666/shapecolor-color/shadow-1/border-dark/symbolstyle-white/symbolshadowstyle-dark/gradient-iphone/number_'+num+'.png";\n') #replace with comment above  to go back to default icon
    if windowtext !=None:
        f.write('\t\tvar info = '+'"'+windowtext+'"'+';\n')
    f.write('\t\tvar infowindow = new google.maps.InfoWindow({\n')
    f.write('\t\t});\n')
    f.write('\t\tvar marker = new google.maps.Marker({\n')
    if title !=None:
        f.write('\t\ttitle: "'+str(title)+'",\n')
    f.write('\t\ticon: img,\n')
    f.write('\t\tposition: latlng,\n')
    f.write('\t\tmap: map,\n')
    f.write('\t\tcontent: info\n')
    f.write('\t\t});\n')
    f.write('\t\tmarker.setMap(map);\n')
    f.write('\n')
    f.write('\t\tgoogle.maps.event.addListener(marker, "click", function(content) {\n')
    f.write('\t\t\tinfowindow.setContent(this.content);\n')
    f.write('\t\t\tinfowindow.open(map,this);\n')
    f.write('\t\t});\n')

mymap.addpoint 一个额外的参数self ,因为它是一个实例方法。 因此,您要在那里传递7个参数。

Python方法有一个额外的参数self mymap.addpoint()方法采用self以及其他五个参数。

您传入了六个,加上bound方法的第一个参数self产生了七个。

请注意,该异常发生在mymap.addpoint()方法上, 而不是您的自定义maps.drawpoint()方法(该方法maps.drawpoint() 7个参数)中; 请注意此处方法名称的差异。

mymap.addpoint()更改的项目文档来看,您还更改了mymap.addpoint() ,它通常仅需要4个参数(不计算self )。

不要让错误消息迷惑您,当您在python对象上调用实例方法时,第一个参数将始终是self ,您不会显式传递它。 因此,实际上只允许您传递5个参数,但使用6个参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM