constant-0.0.4
توضیحات
Use IDLE autocomplete feature to manage large amount of constants.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | Unix |
| نام فایل | constant-0.0.4 |
| نام | constant |
| نسخه کتابخانه | 0.0.4 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | Sanhe Hu |
| ایمیل نویسنده | husanhe@gmail.com |
| آدرس صفحه اصلی | https://github.com/MacHu-GWU/constant-project |
| آدرس اینترنتی | https://pypi.org/project/constant/ |
| مجوز | MIT |
.. image:: https://travis-ci.org/MacHu-GWU/constant-project.svg?branch=master
.. image:: https://img.shields.io/pypi/v/constant.svg
.. image:: https://img.shields.io/pypi/l/constant.svg
.. image:: https://img.shields.io/pypi/pyversions/constant.svg
Welcome to constant Documentation
===============================================================================
If you have lots of constant value widely used across your development. A better way is to define ``Constant Variable`` rather than using the raw value. This will improve the readability of your codes.
``constant`` is a library provide extensive way of managing your constant.
Example:
.. code-block:: python
from constant import Constant
from constant.pkg.sixmini import PY3
class Food(Constant):
class Fruit(Constant):
id = 1
name = "fruit"
class Apple(Constant):
id = 1
name = "apple"
class RedApple(Constant):
id = 1
name = "red apple"
class GreenApple(Constant):
id = 2
name = "green apple"
class Banana(Constant):
id = 2
name = "banana"
class YellowBanana(Constant):
id = 1
name = "yellow banana"
class GreenBanana(Constant):
id = 2
name = "green banana"
class Meat(Constant):
id = 2
name = "meat"
class Pork(Constant):
id = 1
name = "pork"
class Meat(Constant):
id = 2
name = "meat"
You can visit it's data or child class data in these way.
.. code-block:: python
>>> Fruit.items() # .items() return it's data
[('id', 1), ('name', 'fruit')]
>>> Fruit.keys() # .keys() return keys
['id', 'name']
>>> Fruit.keys() # .values() return values
[1, 'fruit']
>>> Fruit.to_dict() # return data in a dict
{'id': 1, 'name': 'fruit'}
# iterate on all child class
>>> Fruit.collection(sort_by='id')
[class Apple, class Banana]
# get first child class that kls.id == 1
# useful when you need reverse lookup
>>> Fruit.get('id', 1)
class Apple
>>> Fruit.get('id', 1, multi=True) # get all child class that kls.id == 1
[class Apple, ]
**Quick Links**
-------------------------------------------------------------------------------
- `GitHub Homepage <https://github.com/MacHu-GWU/constant-project>`_
- `Online Documentation <http://pythonhosted.org/constant>`_
- `PyPI download <https://pypi.python.org/pypi/constant>`_
- `Install <install_>`_
- `Issue submit and feature request <https://github.com/MacHu-GWU/constant-project/issues>`_
- `API reference and source code <http://pythonhosted.org/constant/py-modindex.html>`_
.. _install:
Install
-------------------------------------------------------------------------------
``constant`` is released on PyPI, so all you need is:
.. code-block:: console
$ pip install constant
To upgrade to latest version:
.. code-block:: console
$ pip install --upgrade constant
نحوه نصب
نصب پکیج whl constant-0.0.4:
pip install constant-0.0.4.whl
نصب پکیج tar.gz constant-0.0.4:
pip install constant-0.0.4.tar.gz