python - 在Django中定义全局对象
怪我咯
怪我咯 2017-04-17 16:48:46
0
1
633
怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
Ty80

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
内容为:

# 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 calculatorfrom calculator import *The content is:
rrreee

Usage method import calculator or from calculator import * can be used🎜Not limited to Django🎜
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!