Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Flask SQLAlchemy中添加_init__()方法_Python_Python 3.x_Flask_Flask Sqlalchemy - Fatal编程技术网

Python 在Flask SQLAlchemy中添加_init__()方法

Python 在Flask SQLAlchemy中添加_init__()方法,python,python-3.x,flask,flask-sqlalchemy,Python,Python 3.x,Flask,Flask Sqlalchemy,我在Python3.6.5中使用Flask SQLAlchemy,到目前为止,还不能通过调用\uuuu init\uuuu()来扩展模型。我的代码如下所示: ''' file: models.py ''' from flask_sqlalchemy import SQLAlchemy db = SQLAlchemy() class Network(db.Model): __tablename__ = 'network' id = db.Column(db.Integer, p

我在Python3.6.5中使用Flask SQLAlchemy,到目前为止,还不能通过调用
\uuuu init\uuuu()
来扩展模型。我的代码如下所示:

'''
file: models.py
'''
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()

class Network(db.Model):
    __tablename__ = 'network'

    id = db.Column(db.Integer, primary_key=True)
    baud_rate = db.Column(db.Integer)

    def __init__(**kwargs):
        super(Network, self).__init__(**kwargs)  # see note
尝试实例化网络对象会导致错误:

>>> n = Network(baud_rate=300)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: __init__() takes 0 positional arguments but 1 was given

。。。但是这没有任何区别。

听起来像是医生忘记了在
\uuuuu init\uuuuuuuu
中提到
self
属性(一个在五月被接受):


是的,这就成功了。不过,和我预想的不太一样!
def __init__(**kwargs):
    super().__init__(**kwargs)
class Network(db.Model):
    __tablename__ = 'network'

    id = db.Column(db.Integer, primary_key=True)
    baud_rate = db.Column(db.Integer)

    def __init__(self, **kwargs):
        super().__init__(**kwargs)