How much sanity checking is required for function inputs?
Marko Rauhamaa
marko at pacujo.net
Sun Apr 24 01:56:24 EDT 2016
Steven D'Aprano <steve at pearwood.info>:
> On Sun, 24 Apr 2016 12:03 pm, Christopher Reimer wrote:
>
>> On 4/23/2016 2:33 PM, Matt Wheeler wrote:
>>> This is still backwards to me. It prevents your classes from being
>>> suitable for restoring a stored game state, not just custom starting
>>> positions (which I think is what Ethan means by custom setups).
>>
>> I haven't thought that far about saving the game state. I'm under the
>> impression that pickle (or something else) would save and load the
>> instantiated object of each piece. If that's not the case, I'll change
>> the code then.
>
> Pickle will do what you are thinking of, but pickle is not secure and
> involves executing arbitrary code. If you cannot trust the source of
> the pickle, then you should not use it.
You shouldn't use your runtime objects as a storage format. Instead,
design the storage objects separately and translate between runtime and
storage objects as needed.
JSON objects or straight Python dicts are good candidates for overall
storage format. JSON would allow for easy interchange between different
programming languages if need be.
Marko
More information about the Python-list
mailing list