1. Introduction to the Field class
① The Field object specifies the metadata (any metadata) of each field, and the values accepted by the Field object have no restrictions
②The main purpose of setting the Field object is to define all metadata in one place
③ Note that the Field object that declares the item is not assigned a class attribute. (accessible via item.fields )
④The Field class is just an alias of the built-in dictionary class (dict) , and does not provide additional methods and attributes . Used to support item life syntax based on class attribute methods.
[Field class source code]
class Field(dict): """Container of field metadata"""
2.Analysis of dict class source code
class internal method
class dict(object): """ dict() -> create empty dictionary dict(mapping) -> initializes a new dictionary {"key":value} from the mapping object's key-value pairs dict(iterable) -> initialize dictionary from iterator d[key] = value dict(**kwargs) -> initialize new dictionary with dictionary """ # 1. Clear everything inside the dictionary -> empty dictionary def clear(self): pass # 2. Copy of dictionary dict def copy(self): """ dict_copy = D.copy()""" pass # 3. Static methods. Returns a new dictionary containing the keys from the iterator, and the corresponding values @staticmethod # known case def fromkeys(*args, **kwargs): # real signature unknown pass # 4. Return the value of the specified key k, if the value is not in the dictionary, return the value of d def get(self, k, d=None): # real signature unknown; restored from __doc__ pass # 5. Return traversable (key, value) pairs as a dictionary def items(self): # real signature unknown; restored from __doc__ pass # 6. Return all the keys of a dictionary as a list def keys(self): # real signature unknown; restored from __doc__ pass # 7. Delete the value corresponding to the given key k in the dictionary, and the return value is the deleted value. The k value must be given. Otherwise, the value of d is returned. def pop(self, k, d=None): # real signature unknown; restored from __doc__ pass # 8. Randomly return and delete a pair of keys and values from the dictionary def popitem(self): # real signature unknown; restored from __doc__ pass # 9. Similar to get(), but if the key k is not present in the dictionary, the key will be added and the value will be set to d def setdefault(self, k, d=None): # real signature unknown; restored from __doc__ pass # 10. Update the key-value pair in dictionary 2 into the calling dictionary def update(self, E=None, **F): # known special case of dict.update """ If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k] """ pass # 11. Return all the values in the dictionary as a dictionary def values(self): # real signature unknown; restored from __doc__ """ D.values() -> an object providing a view on D's values """ pass # 12. Built-in methods. Judging whether the key is in the dictionary, returns True when not returning False def __contains__(self, *args, **kwargs): # real signature unknown pass # 13. Delete the value corresponding to the k key in the dictionary def __delitem__(self, *args, **kwargs): # real signature unknown """ Delete self[key]. """ pass # 14. Returns a dictionary of values that exist def __eq__(self, *args, **kwargs): # real signature unknown """ Return self==value. """ pass def __getattribute__(self, *args, **kwargs): # real signature unknown """ Return getattr(self, name). """ pass def __getitem__(self, y): # real signature unknown; restored from __doc__ """ x.__getitem__(y) <==> x[y] """ pass def __ge__(self, *args, **kwargs): # real signature unknown """ Return self>=value. """ pass def __gt__(self, *args, **kwargs): # real signature unknown """ Return self>value. """ pass def __init__(self, seq=None, **kwargs): # known special case of dict.__init__ pass def __iter__(self, *args, **kwargs): # real signature unknown """ Implement iter(self). """ pass def __len__(self, *args, **kwargs): # real signature unknown """ Return len(self). """ pass def __le__(self, *args, **kwargs): # real signature unknown """ Return self<=value. """ pass def __lt__(self, *args, **kwargs): # real signature unknown """ Return self<value. """ pass @staticmethod # known case of __new__ def __new__(*args, **kwargs): # real signature unknown """ Create and return a new object. See help(type) for accurate signature. """ pass def __ne__(self, *args, **kwargs): # real signature unknown """ Return self!=value. """ pass def __repr__(self, *args, **kwargs): # real signature unknown """ Return repr(self). """ pass def __setitem__(self, *args, **kwargs): # real signature unknown """ Set self[key] to value. """ pass def __sizeof__(self): # real signature unknown; restored from __doc__ """ D.__sizeof__() -> size of D in memory, in bytes """ pass __hash__ = None
Python's built-in functions for working with dictionaries
# 15. Calculate the number of dictionary elements, that is, the total number of keys def len(*args, **kwargs): # real signature unknown """ Return the number of items in a container. """ pass # 16. Determine the dictionary type (equivalent to calling the __init__() initialization method in the type class) def __init__(cls, what, bases=None, dict=None): # known special case of type.__init__ """ type(object_or_name, bases, dict) type(object) -> the object's type type(name, bases, dict) -> a new type # (copied from class doc) """ pass