Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.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 类型错误:';str';对象在创建peewee模型时不可调用_Python_Python 3.x_Peewee - Fatal编程技术网

Python 类型错误:';str';对象在创建peewee模型时不可调用

Python 类型错误:';str';对象在创建peewee模型时不可调用,python,python-3.x,peewee,Python,Python 3.x,Peewee,我目前正在做我自己的小项目,就是点击一个毫无意义的按钮。我正在用python使用tkinter和peewee来存储保存,以便用户/玩家可以从他们离开的地方继续 当我执行“保存”功能时,但当我在peewee中创建模型时,它给了我一个错误: TypeError:“str”对象不可调用 我的模型类如下所示: db = SqliteDatabase("scores.db") class Score(Model): save = CharField() score = IntegerF

我目前正在做我自己的小项目,就是点击一个毫无意义的按钮。我正在用python使用tkinter和peewee来存储保存,以便用户/玩家可以从他们离开的地方继续

当我执行“保存”功能时,但当我在peewee中创建模型时,它给了我一个错误:

TypeError:“str”对象不可调用

我的模型类如下所示:

db = SqliteDatabase("scores.db")


class Score(Model):
    save = CharField()
    score = IntegerField()

    class Meta:
        database = db
def save_progress():
    global score_number
    # score_number signifies the score of the game(how many times the button has been clicked)
    saves_length = int(Score.select().count())
    save = "save{}".format(saves_length+1)
    Score.create(save=save, score=score_number)
Score.create(save=save, score=score_number)
保存进度的函数如下所示:

db = SqliteDatabase("scores.db")


class Score(Model):
    save = CharField()
    score = IntegerField()

    class Meta:
        database = db
def save_progress():
    global score_number
    # score_number signifies the score of the game(how many times the button has been clicked)
    saves_length = int(Score.select().count())
    save = "save{}".format(saves_length+1)
    Score.create(save=save, score=score_number)
Score.create(save=save, score=score_number)
错误出现在以下行:

db = SqliteDatabase("scores.db")


class Score(Model):
    save = CharField()
    score = IntegerField()

    class Meta:
        database = db
def save_progress():
    global score_number
    # score_number signifies the score of the game(how many times the button has been clicked)
    saves_length = int(Score.select().count())
    save = "save{}".format(saves_length+1)
    Score.create(save=save, score=score_number)
Score.create(save=save, score=score_number)
我不明白为什么它说我调用字符串对象,因为我认为我不是

有人能给我解释一下我在代码中做错了什么吗

谢谢


Andrei

Score类有一个名为save的函数,您将其更改为str。稍后会调用它将行存储到数据库中

class Score(Model):
    save = CharField()
见文件

字段命名冲突

模型类实现了许多类和实例方法,例如Model.save()或Model.create()。如果声明的字段名称与模型方法一致,则可能会导致问题。考虑: