据我所知,我只给出了我的函数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')
答案 0 :(得分:2)
mymap.addpoint
有一个额外的参数self
,因为它是一个实例方法。因此,你在那里传递了7个参数。
答案 1 :(得分:1)
Python方法有一个额外的参数self
。 mymap.addpoint()
方法需要self
加上五个其他参数。
你传递的是6,加上绑定方法,第一个参数self
生成七个。
请注意,对于自定义 mymap.addpoint()
方法(确实需要7个参数),maps.drawpoint()
方法不会发生异常;请注意方法名称的不同之处。
根据未改变的project documentation判断,您也改变了mymap.addpoint()
,通常只需要4个参数(不计算self
)。
答案 2 :(得分:0)
当你在python对象上调用实例方法时,不要让错误消息欺骗你,第一个参数永远是self
你没有明确传递的。因此,实际上只允许传递5个参数,但使用的是6。