Framsreader (moved to Bitbucket)
Python3 file reader for Framsticks
From PyPI:
pip3 install framsreader
git clone https://github.com/ebonyclock/framsreader
cd framsreader
pip3 install .
or without cloning the repository:
pip3 install git+https://github.com/ebonyclock/framsreader
Just copy/symlink framsreader subdirectory to your project e.g.
git clone https://github.com/ebonyclock/framsreader REPO_ROOT
# copy:
cp -r REPO_ROOT/framsreader YOUR_PROJECT
# symlink:
ln -s REPO_ROOT/framsreader YOUR_PROJECT
import framsreader as fr
# Parsing directly from a file
objects = fr.load("example_file.expdef")
# Parsing a string:
objects = fr.loads("classname:\nprop1:1\nprop2:123\n")
By default all string representing numerals are cast to integers or floats. To disable this behavior use 'autocast=False':
import framsreader as fr
input_string = "class:\n" \
"int_prop: 1e5\n" \
"float_prop: 123.3\n"\
"str_prop: whatever"
print(fr.loads(input_string))
print(fr.loads(input_string, autocast=False))
Effect (note that int_prop and float_prop are kept as strings when autocast=False):
[{'_classname': 'class', 'str_prop': 'whatever', 'int_prop': 100000.0, 'float_prop': 123.3}]
[{'_classname': 'class', 'str_prop': 'whatever', 'int_prop': '1e5', 'float_prop': '123.3'}]
By default, the context will be determined based on the file extension and read from framscript.xml. Additionally you can change the context arbitrarily using 'context' parameter:
import framsreader as fr
input_string = "expdef:\n" \
"name: 100\n"
print(fr.loads(input_string))
print(fr.loads(input_string, context="expdef file"))
Not that "name" field is left as a string because of the context.
[{'name': 100, '_classname': 'expdef'}]
[{'name': '100', '_classname': 'expdef'}]