当前位置:   article > 正文

python3_scrapy包Field类方法及属性剖析、字典(dict)类方法及属性剖析_scrapy.field

scrapy.field

1.Field类简介

Field对象指明了每个字段的元数据(任何元数据),Field对象接受的值没有任何限制

②设置Field对象的主要目就是在一个地方定义好所有的元数据

③注意,声明item的Field对象,并没有被赋值成class属性。(可通过item.fields进行访问)

④Field类仅是内置字典类(dict)的一个别名,并没有提供额外的方法和属性。被用来基于类属性的方法来支持item生命语法。

【Field类源码】

  1. class Field(dict):
  2. """Container of field metadata"""

2.dict类源码剖析

类内部方法

  1. class dict(object):
  2. """
  3. dict() -> 创建空字典
  4. dict(mapping) -> 从映射对象的键值对中初始化新字典{"key":value}
  5. dict(iterable) -> 从迭代器初始化字典 d[key] = value
  6. dict(**kwargs) -> 使用字典初始化新字典
  7. """
  8. # 1.清除字典内部所有内容 -> 空字典
  9. def clear(self):
  10. pass
  11. # 2.字典dict的复制
  12. def copy(self):
  13. """ dict_copy = D.copy()"""
  14. pass
  15. # 3.静态方法。返回一个新的字典,其中包含来自迭代器的键,以及对应的值
  16. @staticmethod # known case
  17. def fromkeys(*args, **kwargs): # real signature unknown
  18. pass
  19. # 4.返回指定键k的值,如果值不在字典中返回d的值
  20. def get(self, k, d=None): # real signature unknown; restored from __doc__
  21. pass
  22. # 5.以字典形式返回可遍历的(键,值)对
  23. def items(self): # real signature unknown; restored from __doc__
  24. pass
  25. # 6.以列表形式返回一个字典所有的键
  26. def keys(self): # real signature unknown; restored from __doc__
  27. pass
  28. # 7.删除字典给定键k所对应的值,返回值为被删除的值。k值必须给出。否则,返回d值。
  29. def pop(self, k, d=None): # real signature unknown; restored from __doc__
  30. pass
  31. # 8.随机返回并删除字典中的一对键和值
  32. def popitem(self): # real signature unknown; restored from __doc__
  33. pass
  34. # 9.和get()类似, 但如果键k不存在于字典中,将会添加键并将值设为d
  35. def setdefault(self, k, d=None): # real signature unknown; restored from __doc__
  36. pass
  37. # 10.将字典2中的键值对更新入调用字典中
  38. def update(self, E=None, **F): # known special case of dict.update
  39. """
  40. If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
  41. If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
  42. In either case, this is followed by: for k in F: D[k] = F[k]
  43. """
  44. pass
  45. # 11.以字典的形式返回字典中所有的值
  46. def values(self): # real signature unknown; restored from __doc__
  47. """ D.values() -> an object providing a view on D's values """
  48. pass
  49. # 12.内置方法。判断键是否在字典中,在返回True,不在返回False
  50. def __contains__(self, *args, **kwargs): # real signature unknown
  51. pass
  52. # 13.删除字典中对应k键的值
  53. def __delitem__(self, *args, **kwargs): # real signature unknown
  54. """ Delete self[key]. """
  55. pass
  56. # 14.返回存在Value值得字典
  57. def __eq__(self, *args, **kwargs): # real signature unknown
  58. """ Return self==value. """
  59. pass
  60. def __getattribute__(self, *args, **kwargs): # real signature unknown
  61. """ Return getattr(self, name). """
  62. pass
  63. def __getitem__(self, y): # real signature unknown; restored from __doc__
  64. """ x.__getitem__(y) <==> x[y] """
  65. pass
  66. def __ge__(self, *args, **kwargs): # real signature unknown
  67. """ Return self>=value. """
  68. pass
  69. def __gt__(self, *args, **kwargs): # real signature unknown
  70. """ Return self>value. """
  71. pass
  72. def __init__(self, seq=None, **kwargs): # known special case of dict.__init__
  73. pass
  74. def __iter__(self, *args, **kwargs): # real signature unknown
  75. """ Implement iter(self). """
  76. pass
  77. def __len__(self, *args, **kwargs): # real signature unknown
  78. """ Return len(self). """
  79. pass
  80. def __le__(self, *args, **kwargs): # real signature unknown
  81. """ Return self<=value. """
  82. pass
  83. def __lt__(self, *args, **kwargs): # real signature unknown
  84. """ Return self<value. """
  85. pass
  86. @staticmethod # known case of __new__
  87. def __new__(*args, **kwargs): # real signature unknown
  88. """ Create and return a new object. See help(type) for accurate signature. """
  89. pass
  90. def __ne__(self, *args, **kwargs): # real signature unknown
  91. """ Return self!=value. """
  92. pass
  93. def __repr__(self, *args, **kwargs): # real signature unknown
  94. """ Return repr(self). """
  95. pass
  96. def __setitem__(self, *args, **kwargs): # real signature unknown
  97. """ Set self[key] to value. """
  98. pass
  99. def __sizeof__(self): # real signature unknown; restored from __doc__
  100. """ D.__sizeof__() -> size of D in memory, in bytes """
  101. pass
  102. __hash__ = None

python处理字典的内置函数

  1. # 15.计算字典元素个数,即键的总数
  2. def len(*args, **kwargs): # real signature unknown
  3. """ Return the number of items in a container. """
  4. pass
  5. # 16.判断字典类型(相当于调用了type类中的__init__()初始化方法)
  6. def __init__(cls, what, bases=None, dict=None): # known special case of type.__init__
  7. """
  8. type(object_or_name, bases, dict)
  9. type(object) -> the object's type
  10. type(name, bases, dict) -> a new type
  11. # (copied from class doc)
  12. """
  13. pass
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/328001?site
推荐阅读
相关标签
  

闽ICP备14008679号