예제 #1
0
assert prefs.X == 1 and prefs.Y == 2  # True

# By setting the following attributes, their new values are
# automatically stored into the file.
prefs.X = 3
prefs.Y = 4

# attributes can be defined without default values.
prefs.Z = 5

# RESTART program (re-initializing 'prefs' gives the same results as
#                  restarting. Since defaults are stored, you are not
#                  required to give them default values again.
#                  However, when restarting the script, this is
#                  usually unavoidable. )
prefs = Preferences(defaults=prefs_defaults, filename="preferences_test.txt")

# Old values have been remembered.
assert prefs.X == 3 and prefs.Y == 4 and prefs.Z == 5  # True

# Following method resets ALL values (if no arguments are given),
# although it will be unable to reset "Z", as it has no default.
prefs.reset_to_default()
assert prefs.X == 1 and prefs.Y == 2 and prefs.Z == 5  # True

# If you'd like to remove the stored file, the following method
# would accomplish this. (This removes any old values!!)
prefs.delete_preferences_file()

# written in python 3.5.2