小编Zaz*_*ous的帖子

Python对象的多个实例的作用类似于同一个实例

我这里有我的班级模板:

 import sqlite3

class Patron(object):
    #Let's set some basic attributes
    attributes = { "patron_id" : None,
    "name" : None,
    "address" : None,
    "phone" : None,
    "email" : None,
    "fee_balance" : None,
    "fees_per_day" : None,
    "books_checked_out" : [],
    "books_overdue" : []}

    def __init__(self):
        #Create a empty instance
        pass

    def new(self, patron_id, name, address, phone, email):
        #Create an instance with new values
        self.attributes["patron_id"] = patron_id
        self.attributes["name"] = name
        self.attributes["address"] = address
        self.attributes["phone"] = phone
        self.attributes["email"] = email

    def retrieve(self, patron_id):
        #Connect to …
Run Code Online (Sandbox Code Playgroud)

python arguments default behavior mutable

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

标签 统计

arguments ×1

behavior ×1

default ×1

mutable ×1

python ×1