TypeError:Person()不接受任何参数

时间:2018-12-27 12:06:18

标签: python

我是python的新手,正在尝试创建class。每次运行此代码时都会出错TypeError:Person()不带任何参数。 我不知道为什么参数不能传递给类

class Person:
    def _init_(self,name,age):
        self.name=name
        self.age=age
    def myfun(self):
        print("my name is"+self.name)
        print("my age is"+self.age)

p1=Person("John",29)
p1.myfun()

2 个答案:

答案 0 :(得分:3)

构造函数必须命名为__init__,而不是_init_

答案 1 :(得分:0)

您应该再添加1个library(shiny) library(shinydashboard) library(shinydashboardPlus) library(leaflet) library(tidyverse) datafile<- read.csv("/Users/prabeshkc/Desktop/stackoverflow data.csv") `ui<- dashboardPage( skin = "blue", dashboardHeader(title = "Cluster Map"), dashboardSidebar( selectInput("Area",label = "Geo Area", choices = datafile$geoArea) ), dashboardBody( fluidRow(box(width = 12,leafletOutput(outputId = "mymap"))) ))` `server <- function(input, output) { data_input<-reactive({ datafile %>% leaflet() %>% addTiles() %>% addMarkers(lng = datafile$lng,lat = datafile$lat) }) data_input_ordered<-reactive({ data_input()[order(match(data_input)$geoArea)] })` `labels<- reactive({ paste("<p>", datafile$goals,"</p>"), paste("<p>", datafile$achieved,"</p>") })` `output$mymap<- renderLeaflet( datafile %>% leaflet() %>% addTiles() %>% addCircleMarkers(lng = datafile$lng,lat = datafile$lat) ) } shinyApp(ui = ui, server = server)` 来启动其魔术方法,并用两个下划线包裹

https://micropyramid.com/blog/understand-self-and-init-method-in-python-class/

_

有效