我无法使用通常的init () 方法初始化“peewee.Model”后代对象的字段。我该如何初始化?
import peewee
peewee_database = peewee.SqliteDatabase('example.db')
class Config():
def __init__(self, seats, cylinders):
self.seats = seats
self.cylinders = cylinders
class Car(peewee.Model):
magic_number = peewee.IntegerField()
color = peewee.TextField()
class Meta:
database = peewee_database
def __init__(self, config):
self.magic_number = config.seats / config.cylinders
self.color = None
peewee_database.connect()
peewee_database.create_tables([Car])
config = Config(7, 6)
car = Car(config)
car.color = "blue"
car.save()
Run Code Online (Sandbox Code Playgroud)
在 Python3 中产生此错误:
File "test.py", line 27, in <module>
car = Car(config)
File "test.py", line 20, in __init__
self.magic_number = config.seats / …Run Code Online (Sandbox Code Playgroud) 我有99人的年收入数据:
import pandas, random
incomes = pandas.DataFrame({'income':[round(random.triangular(20,80,200),0) for i in range(99)]})
Run Code Online (Sandbox Code Playgroud)
如何:
抱歉,听起来像是一个新手问题。我在学。谢谢你!