zoukankan      html  css  js  c++  java
  • data is not None

    在读django的form源码:

    def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
                 initial=None, error_class=ErrorList, label_suffix=None,
                 empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None):
        self.is_bound = data is not None or files is not None
        self.data = data or {}
        self.files = files or {}
        self.auto_id = auto_id
        if prefix is not None:
            self.prefix = prefix
        self.initial = initial or {}
        self.error_class = error_class
        # Translators: This is the default suffix added to form field labels
        self.label_suffix = label_suffix if label_suffix is not None else _(':')
        self.empty_permitted = empty_permitted
        self._errors = None  # Stores the errors after clean() has been called.
    
        # The base_fields class attribute is the *class-wide* definition of
        # fields. Because a particular *instance* of the class might want to
        # alter self.fields, we create self.fields here by copying base_fields.
        # Instances should always modify self.fields; they should not modify
        # self.base_fields.
        self.fields = copy.deepcopy(self.base_fields)
        self._bound_fields_cache = {}
        self.order_fields(self.field_order if field_order is None else field_order)
    

    发现self.is_bound = data is not None

    Microsoft Windows [版本 10.0.17134.285]
    (c) 2018 Microsoft Corporation。保留所有权利。
    
    C:UsersRoc Sun>python
    Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> lis = []
    >>> dic = {}
    >>> print(lis is not None)
    True
    >>> print(lis is not None)
    True
    >>> dic['a'] = 111
    >>> print(dic)
    {'a': 111}
    >>> print(dic is not None)
    True
    >>> lis = None
    >>> print(lis)
    None
    >>> print(lis is not None)
    False
    >>>
    
    • 空列表,空字典都是True
    • None是Ture

    这里的None是指None,而不是空字符串,空列表,空元组,空字典等。

  • 相关阅读:
    Debian Linux 5 时间设定相关与时间同步
    javascript的基本类型
    判断浏览器的类型
    用C#打开IE
    MAC ADDRESS LOOKUP
    HP大中华区总裁辞职信
    原始的JavaScript创建
    .NET应用程序域
    显示接口实现与隐式接口实现
    [转载]MVC Razor 语法(转)
  • 原文地址:https://www.cnblogs.com/linga/p/9698120.html
Copyright © 2011-2022 走看看