Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nurdok/basicstruct
A simple struct-like object for Python
https://github.com/nurdok/basicstruct
Last synced: about 1 month ago
JSON representation
A simple struct-like object for Python
- Host: GitHub
- URL: https://github.com/nurdok/basicstruct
- Owner: Nurdok
- License: mit
- Created: 2015-08-03T20:47:44.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-24T18:45:28.000Z (over 7 years ago)
- Last Synced: 2024-07-06T16:07:40.800Z (4 months ago)
- Language: Python
- Size: 20.5 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
basicstruct
===========.. image:: https://travis-ci.org/Nurdok/basicstruct.svg
:target: https://travis-ci.org/Nurdok/basicstruct.. image:: https://coveralls.io/repos/Nurdok/basicstruct/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/Nurdok/basicstruct?branch=master.. image:: https://badge.fury.io/py/basicstruct.svg
:target: http://badge.fury.io/py/basicstruct
A simple struct-like object for Python.
Compatible with Python 2.6+, 3.x, pypy and pypy3.Installation
^^^^^^^^^^^^.. code-block:: python
pip install basicstruct
Usage
^^^^^To create your own struct, inherit from `BasicStruct` and define the field with the `__slots__` class member.
`BasicStruct` are efficient objects that are automatically comparable, hashable, picklable, printable and reprable... code-block:: python
from basicstruct import BasicStruct
class Point(BasicStruct):
__slots__ = ('x', 'y')
p1 = Point(2, 3)
p2 = Point(1, y=6)
p3 = Point(x=0, y=0)
print(p1) # prints: Point(x=2, y=3)