cloudymax / orm-events

File I/O helpers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ORM-Events


Attemptes to recreate C# getter/setter wich will generate events docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/using-properties https://docs.microsoft.com/en-us/dotnet/standard/events/

Usage

  • See demo.py for serialization, de-serialization, and format conversion examples.

To Run the demo:

# cd to the program folder
cd io_tools

# install dependencies
pip3 install -r requirements.txt

# run the script
python3 demo.py

Step by step in:

python3
import io_tools as io
import json

settings = {}
vars = io.Variables(settings)
vars.debug = True
vars.go_steppy = False
vars.yaml_input_file = "pref_input_test.yaml"
vars.json_input_file = "cache.json"

# reads a file of TYPE
vars.yaml_file_contents = io.read_yaml_file(vars.yaml_input_file)
vars.json_file_contents = io.read_json_file(vars.json_input_file)

# print as pretty json
io.print_pretty(vars.json_file_contents, vars.debug, "json")
io.print_pretty(vars.yaml_file_contents, vars.debug, "json")

# print as compact json
print(vars.__dict__)

# Serialize
json_string = print(vars.__dict__) 
io.write_file('cache.json', vars.__dict__, vars.debug)

# Can write CSVs as well, but only working properly on non-nested files. WIP.
csv = io.json_to_csv('cache.json')

Class Methods


Datastore

Datastore is a <key>:<value> dict that accepts any types and is used for portability. It achieves this by storing all variables in a generic dictionary with the change() method overriden to be an event system.

Variables

Object that holds a list of Datastore()s, When eneabled, the built-in go_steppy() function will pause script execution on any memory state change to provide a json formatted diff. for example:

go_steppy

change_value: Triggered when any variable within the Datastore() is updated, or created. get_current_value: Returns the current value of a variable within the Datastore(), and triggers an event. diff_values: When enabled, deepdiffs the current and proposed change to the Datastore() object

About

File I/O helpers


Languages

Language:Python 100.0%