<p>也许{a1}就是你要搜索的。在</p>
<p>支持str、int、float、datetime
const字段实例将保持其基类型行为。
和orm模型定义一样,BaseConst是管理常量字段的常量助手。在</p>
<p>例如:</p>
<pre><code>from __future__ import print_function
from kkconst import (
BaseConst,
ConstFloatField,
)
class MathConst(BaseConst):
PI = ConstFloatField(3.1415926, verbose_name=u"Pi")
E = ConstFloatField(2.7182818284, verbose_name=u"mathematical constant") # Euler's number"
GOLDEN_RATIO = ConstFloatField(0.6180339887, verbose_name=u"Golden Ratio")
magic_num = MathConst.GOLDEN_RATIO
assert isinstance(magic_num, ConstFloatField)
assert isinstance(magic_num, float)
print(magic_num) # 0.6180339887
print(magic_num.verbose_name) # Golden Ratio
# MathConst.GOLDEN_RATIO = 1024 # raise Error, because assignment allow only once
</code></pre>
<p>更多详细用法您可以阅读pypi url:
<a href="https://pypi.python.org/pypi/kkconst" rel="nofollow noreferrer"> pypi </a>或<a href="https://github.com/kaka19ace/kkconst" rel="nofollow noreferrer"> github </a></p>
<p>同样的答案:<a href="https://stackoverflow.com/questions/2682745/creating-constant-in-python/34433971#34433971"> Creating constant in Python </a></p>