Repository navigation
Basic Usage
There are many ways to use Fancy Config, but here is a basic example:
Example.py
from fancy_config import read_data
print(read_data("FOOD","./example.fconfig")) # Example usage of the function
print(read_data("FNUM","./example.fconfig"))Example.fconfig
# This is a comment in the .fconfig format. This doesn't have to be this format, but in this example it is for clarity.
FOOD| What is your favorite food? <Pizza>
FNUM|INT| What is your favorite amount of food? <3.14159>
Running the above code should have this result:
Pizza
Could not convert 3.14159 to int. Invalid Config. Key: FNUM. Line: 3
This error is supposed to happen, as it says FNUM|INT| What.... The INT Section attempts to convert it, no matter what it is, to an int.
For any more advanced type handling, you can get our raw output with like:
Example.fconfig
FNUM|INT| What is your favorite amount of food? <3.14159>
Example.py
from fancy_config import read_data
print(round(read_data("FNUM","./example.fconfig"))) # Example custom type handlingIf your making a software that is likely to be used by people that don't have that much technical knowledge, it is good to know how to make good human readable config files.
The good thing is that Fancy Config makes that easy, being also plain English (except for the key and optional type identifiers).
For example, you could have the following config:
# Star Settings
MINOS|Minimum number of stars <250>
MANOS|Maximum number of stars <500>
TMFSR|Frames between checks for Star death: <60> Frames
REMAS|Chance of a star destruction, 1 in <5>
The config just shown is very easy to understand, the only thing that may be confusing is the part to the left, however, the user shouldn't be interacting with that part anyway.
You can use four different forced data types with Fancy Config with the optional Type Indentifiers.
With Type Indentifiers, an example file may look like this:
SIZEX|INT| Monitor X Px amount: <1920>
SIZEY|INT| Monitor Y Px amount: <1080>
STRTM|INT| Number of star templates to be loaded: <3>
# Image Settings
LEVL0|STR| Image used for level 0 planets: <./img/l0.png>
LEVL1|STR| Image used for level 1 planets: <./img/l1.png>
Here are the avaliable Type Identifiers:
- INT/int | Interature
- STR/str | String
- BOOL/bool | Boolean
- FLOAT/float | Floating Point Number