Skip to content

aleppax/upyftsconf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 

Repository files navigation

micropython Far Too Simple Config File!

uPyftsConf

micropython Far Too Simple Config File

a simplicistic way of storing configuration data for projects written in micropython. (single file, 92 lines of code).

Disclaimer

don't take this script too seriously: even if it does what it's supposed to, it does it in a way that's not at all ordinary. But isn't it fascinating to think that code can rewrite itself?

How it works

copy the file config.py inside a "libs" folder, import it.

If you prefer you can edit the file by adding as many dictionaries as you wish before the lines with code, those are factory settings but can be modified afterwards.

You can also add new dictionaries or settings simply by using the method set(dictionary_name, key_name, value) If the dictionary doesn't exist, it creates it and adds the key:value pair.

The function set writes the new settings both in memory and to the configuration file (config.py), then reloads the module itself.

# example
from libs import config
config.set('upyftsconf','I','exist')

the file config.py writes these lines inside itself:

upyftsconf = {
    'I' : 'exist',
}

Do not nest collection items inside dictionaries. Do not write below this banner: (and do not delete it)

#########################################
### micropython far too simple config ###
###  do not write below this header   ###

Usage

from libs import config
config.set('dict_name','key','value')
myvalue = config.dict_name['key']
# or
myvalue = config.dict_name.get('key')

About

micropython far too simple config file

Topics

Resources

License

Stars

Watchers

Forks

Languages