Self-modifying Python code to keep track of high scores -
i've considered storing high scores game variables in code rather text file i've done far because means less additional files required run , attributing 999999 points becomes harder.
however, require me run self-modifying code overwrite global variables representing scores permanently. looked , considering want change global variables, stuff found advanced.
i'd appreciate if give me explanation on how write self-modifying python code just that, preferably example aids understanding.
my first inclination "don't that". self-modifying python (really language) makes extremely difficult maintain versioned library.
- you make bug fix , need redistribute - how merge data stored via self-modification.
- very hard authenticate packaging using hash - once local version modified it's hard tell version originated because shas won't match.
- it's unsafe - save , load python class that's not stored package, however, if it's user writable, foreign process add arbitrary python code file evaluate. kind of sql injection python style.
python makes trivial load , dump json files, simple things, wouldn't think of else. csv files trivial , can bound maps can more manipulated data using favorite spreadsheet editor.
my suggestion - don't use self-modifiying python unless you're wanting experiment; it's not practical solution in real world, unless you're working in embedded environment disk , memory premium.
Comments
Post a Comment