不明白此错误:未定义名称“人”

时间:2019-06-10 14:30:22

标签: python

我正在尝试运行一个名为person的类。错误为name 'person' is not defined。我该如何解决这个问题?

class person:
    person.count = 0
    def __init__(self,gender,location,DOB):
        # this is constructor method
        self.__gender = gender
        self.__location = location
        self.__DOB = DOB
        # to make the variable inaccessible from out of the class 
        # we have to prefix it with at least two underscores
        print(person.__self)
        print(person.__DOB)
        person.count += 1
    def getname(self):
        #this is access method
        return person.__self
    def getDOB(self):
        return person.__DOB
    def _del_(self):
        print('deleted')

1 个答案:

答案 0 :(得分:1)

首先,将 //FUNCTION TO POPULATE THE TABLE WITH THE DATA function Grid_Table_Populator() { //Populdate the Datatable with the WEB Feed data $("#home_grid").jqGrid({ url: "/Web_Feed_Data", datatype: "json", mtype: "GET", colNames: ["ID", "PROVIDER", "Title"], colModel: [ { name : "ID", align : "center", search : true, hidden : true }, { name : "PROVIDER", align : "center", width : "120%", type : "text", search : true, template: multiselectTemplate }, { name : "TITLE", align : "center", search : true, width : "250%", formatter: Title_Url_Bind }, ], pager : "#home_pager", loadonce : true, shrinkToFit : true, rowNum : 10, autoHeight : true, rowList : [10, 15, 20, 25, 50], sortable : true, sortname : "TITLE", sortorder : "desc", viewrecords : true, toolbar : [true, "top"], autowidth : true, caption : 'Table Data', loadComplete: function(data) { if (!this.ftoolbar) { // create filter toolbar if it isn't exist $(this).jqGrid("filterToolbar", { defaultSearch: "cn", beforeClear: function() { $(this.grid.hDiv) .find(".ui-search-toolbar button.ui-multiselect") .each(function() { $(this).prev("select[multiple]").multiselect("refresh"); }); } }); $(this).triggerHandler("jqGridRefreshFilterValues"); $(this.grid.hDiv) .find(".ui-search-toolbar button.ui-multiselect") .each(function() { $(this).prev("select[multiple]") .multiselect("refresh"); }); } }, }); dataInitMultiselect = function (elem, searchOptions) { var $grid = $(this); setTimeout(function() { var $elem = $(elem), id = elem.id, inToolbar = searchOptions.mode === "filter", options = { selectedList: 2, height: "auto", checkAllText: "all", uncheckAllText: "no", noneSelectedText: "Any", open: function() { var $menu = $(".ui-multiselect-menu:visible"); $menu.width("auto"); var height = $menu.find(">ul>li").first().outerHeight(); $menu.find(">ul").css("maxHeight", 5 * Math.max(height, 12)); return; } }, $options = $elem.find("option"); if ($options.length > 0 && $options[0].selected) { $options[0].selected = false; // unselect the first selected option } if (inToolbar) { options.minWidth = "auto"; } $grid.triggerHandler("jqGridRefreshFilterValues"); $elem.multiselect(options); // replace icons ui-icon-check, ui-icon-closethick, ui-icon-circle-close // and ui-icon-triangle-1-s to font awesome icons var $header = $elem.data("echMultiselect").header; $header.find("span.ui-icon.ui-icon-check") .removeClass("ui-icon ui-icon-check") .addClass("fa fa-fw fa-check"); $header.find("span.ui-icon.ui-icon-closethick") .removeClass("ui-icon ui-icon-closethick") .addClass("fa fa-fw fa-times"); $header.find("span.ui-icon.ui-icon-circle-close") .removeClass("ui-icon ui-icon-circle-close") .addClass("fa fa-times-circle"); $elem.data("echMultiselect") .button .find("span.ui-icon.ui-icon-triangle-1-s") .removeClass("ui-icon ui-icon-triangle-1-s") .addClass("fa fa-caret-down") .css({ float: "right", marginRight: "5px" }); $elem.siblings("button.ui-multiselect").css({ width: "100%", margin: "1px 0", paddingTop: ".3em", paddingBottom: ".3em" }); }, 50); }, multiselectTemplate = { stype: "select", searchoptions: { generateValue: true, //noFilterText: "Any", sopt: ["in"], attr: { multiple: "multiple", size: 3 }, dataInit: dataInitMultiselect } }; } 行放在person.count = 0内。接下来,将每个__init__更改为person(除非是类定义)。