Python reader and parser module for DIP language
Project description
DIPL
This module is a quick reading/parsing tool for Dimensional Input Parameter Language (DIP) that is a part of larger scinumtools project. For more information about DIP, please visit its official documentation. More functionality can be reqested in GitHub Issues.
Reading DIP code
Loading DIP code from a string is straightforward.
>>> import dipl
>>>
>>> text = """
>>> width float = 23.34 cm
>>> age int = 23 yr
>>> !tags ["body"]
>>> """
>>> dipl.load(text)
{
'width': (23.34, 'cm'),
'age': (23, 'yr')
}
It is also possible to change data output format,
>>> from dipl import Format
>>> dipl.load(text, Format.VALUE)
{
'width': 23.34,
'age': 23,
}
or to select only requested nodes using query, or tags:
>>> dipl.load(text, query="width")
{
'width': (23.34, 'cm'),
}
>>> dipl.load(text, tags=["body"])
{
'age': (23, 'yr'),
}
Parsing DIP code
Python dictionaries can be parsed into DIP code, provided that they have a proper structure. An example parsing is shown below.
>>> import dipl
>>> import numpy as np
>>> from scinumtools.units import Quatity
>>>
>>> data = {
>>> 'body': {
>>> 'width': Quantity(172.34, 'cm'),
>>> 'age': (23, 'yr'),
>>> },
>>> 'married': True,
>>> 'name': "John",
>>> 'kids': ["Alice","Williams"],
>>> 'lucky_numbers': np.array([23, 34, 5]),
>>> }
>>> dipl.dump(data)
body
width float = 172.34 cm
age int = 23 yr
married bool = true
name str = "John"
kids str[2] = ["Alice","Williams"]
lucky_numbers int[3] = [23,34,5]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dipl-1.1.0.tar.gz
.
File metadata
- Download URL: dipl-1.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d5f90d36bdc2ee289af486266c471d1338a47e1918651ac9afd5422374b85a7 |
|
MD5 | 8da6619dc66b0349b1acba76f03352cf |
|
BLAKE2b-256 | 82e54296ce4b5f9208922cbe5220b4ddae4629847578ae18efe0b0467c217e88 |
File details
Details for the file dipl-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: dipl-1.1.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 866ce5decdfb499185243a1afefc4c89bc026a6788f49c75307d02f66b913af4 |
|
MD5 | 5d678293de8a6d6c8d76abbc6e395163 |
|
BLAKE2b-256 | 4a57d5135d1958bad2eceb73efbb226a691c6990efc7096656c4b1aeee3c0a8e |