鱼C论坛

 找回密码
 立即注册
查看: 1973|回复: 3

[已解决]关于第十章easygui的EgStore的问题

[复制链接]
发表于 2021-6-6 15:21:57 | 显示全部楼层 |阅读模式
3鱼币
想请教一下
self.restore 和 settings.store 那里没看懂它们哪里跑出来的
实例化对象时为什么要执行self.restore()呢

from easygui import EgStore

class Settings(EgStore):
    def __init__(self,filename):
        self.author = ""
        self.book = ""
        
        self.filename = filename
        self.restore()
        

settingsFilename = "settings.txt"
settings = Settings(settingsFilename)
author = '小甲鱼'
book = '《零基础入门学习Python》'

settings.author = author
settings.book = book
settings.store()
print('\n保存完毕\n')

settingsFilename = 'settings.txt'
settings = Settings(settingsFilename)
print(settings.author)
print(settings.book)
最佳答案
2021-6-6 15:21:58

对 easygui 不怎么了解,刚刚去网上查了下没查到类似文章,去官方看了 easygui 的文档看了得到 restore 的说明文档:

restore()
Set the values of whatever attributes are recoverable from the pickle file.

Populate the attributes (the __dict__) of the EgStore object from the attributes (the __dict__) of the pickled object.

If the pickled object has attributes that have been initialized in the EgStore object, then those attributes of the EgStore object will be replaced by the values of the corresponding attributes in the pickled object.

If the pickled object is missing some attributes that have been initialized in the EgStore object, then those attributes of the EgStore object will retain the values that they were initialized with.

If the pickled object has some attributes that were not initialized in the EgStore object, then those attributes will be ignored.

IN SUMMARY:

After the recover() operation, the EgStore object will have all, and only, the attributes that it had when it was initialized.

Where possible, those attributes will have values recovered from the pickled object.


英语不行......,人机翻译了:

restore()
设置任何可从pickle文件恢复的属性的值。

从pickle对象的属性(__dict__)填充EgStore对象的属性(__dict__)。

如果pickle对象的属性已经在EgStore对象中初始化,那么这些EgStore对象的属性将被pickle对象中相应属性的值所取代。

如果pickle对象丢失了一些在EgStore对象中已经初始化的属性,那么这些EgStore对象的属性将保留初始化时的值。

如果pickle的对象有一些属性没有在EgStore对象中初始化,那么这些属性将被忽略。

总而言之:

在recover()操作之后,EgStore对象将拥有初始化时所拥有的全部且仅有的属性。

在可能的情况下,这些属性将具有从pickle对象中恢复的值。




最佳答案

查看完整内容

对 easygui 不怎么了解,刚刚去网上查了下没查到类似文章,去官方看了 easygui 的文档看了得到 restore 的说明文档: 英语不行......,人机翻译了:
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-6 15:21:58 | 显示全部楼层    本楼为最佳答案   

对 easygui 不怎么了解,刚刚去网上查了下没查到类似文章,去官方看了 easygui 的文档看了得到 restore 的说明文档:

restore()
Set the values of whatever attributes are recoverable from the pickle file.

Populate the attributes (the __dict__) of the EgStore object from the attributes (the __dict__) of the pickled object.

If the pickled object has attributes that have been initialized in the EgStore object, then those attributes of the EgStore object will be replaced by the values of the corresponding attributes in the pickled object.

If the pickled object is missing some attributes that have been initialized in the EgStore object, then those attributes of the EgStore object will retain the values that they were initialized with.

If the pickled object has some attributes that were not initialized in the EgStore object, then those attributes will be ignored.

IN SUMMARY:

After the recover() operation, the EgStore object will have all, and only, the attributes that it had when it was initialized.

Where possible, those attributes will have values recovered from the pickled object.


英语不行......,人机翻译了:

restore()
设置任何可从pickle文件恢复的属性的值。

从pickle对象的属性(__dict__)填充EgStore对象的属性(__dict__)。

如果pickle对象的属性已经在EgStore对象中初始化,那么这些EgStore对象的属性将被pickle对象中相应属性的值所取代。

如果pickle对象丢失了一些在EgStore对象中已经初始化的属性,那么这些EgStore对象的属性将保留初始化时的值。

如果pickle的对象有一些属性没有在EgStore对象中初始化,那么这些属性将被忽略。

总而言之:

在recover()操作之后,EgStore对象将拥有初始化时所拥有的全部且仅有的属性。

在可能的情况下,这些属性将具有从pickle对象中恢复的值。




想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-6-6 16:17:03 | 显示全部楼层


easygui 可以随便过一过,自由性差

唯一优点就是简单了,后期学 Tkinter 或 PyQt5 比这个多了

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2021-6-6 22:33:17 | 显示全部楼层
Twilight6 发表于 2021-6-6 16:17
easygui 可以随便过一过,自由性差

唯一优点就是简单了,后期学 Tkinter 或 PyQt5 比这个多了

额好吧,也快到学Tkinter了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-15 13:04

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表