That is to say, your data life cycle is the python running cycle. In this case, you only need to separate one module (single file or multiple files). For example,calculator.pycalculator.py 内容为:
# coding=utf-8 __all__ = ["cal1"] _g = None class _Calculate(object): def __init__(self): pass def cal1(self): # do some calculate return if _g is None: _g = _Calculate() def cal1(): return _g.cal1()
使用方式import calculator或from calculator import *The content is: rrreee
Usage method
import calculatoror
from calculator import *can be usedNot limited to Django
That is to say, your data life cycle is the python running cycle.
In this case, you only need to separate one module (single file or multiple files).
For example,
calculator.py
calculator.py
内容为:
使用方式
Usage methodimport calculator
或from calculator import *
The content is:rrreee
import calculator
orfrom calculator import *
can be usedNot limited to Django