Giter Site home page Giter Site logo

memory3's Introduction

Memory

A simple smart config manager.

##Simple usage

from memory import Memory

cfg = Memory()
#Creates or reads a file called config.json in the current working directory

#When creating the class, you can define the config parsing engine to use. Currently supported are 'json' and 'toml'.
#Json is available built-in to Python3, toml requires an extra library, which you can get from `pip3 install toml`
#The engine used doesnt change the use of the class, it just changes the output file.
#Toml has some benefits over json in readability and other aspects, but json is more supported and hardened, its personal preference really.

#When creating the class, you can define a specific path for the config file too

cfg = Memory(path='/home/kaiser/MyApp') 
#Creates a file called config.json in the directory if it doesnt exist, otherwise reads the file

cfg = Memory(path='/home/kaiser/MyApp/stuff.json')
#Same as above but makes the filename stuff.json instead

#The Memory class also has a logging var for if you want debug logs in console for each operation

cfg = Memory(logging=True)

cfg._set('score', 1)
#Sets a config variable of score to 1

v = cfg._get('score')
#Returns the config variable for score

v = cfg._get('score', 0)
#Same as above, but defaults to 0 if score does not exist in config

#You can access the config object directly too

cfg['score'] = 10

#But if you edit the object, make sure to save after to save it to the config

cfg.save()

#If the config file was edited, you can reload it in memory

cfg.load()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.