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 calculator or from calculator import * can be used🎜Not 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 used🎜Not limited to Django🎜