Я хочу добавить класс предметов в класс предметов

Я дам технический ответ на ваш вопрос, по крайней мере, с одной возможностью. Используйте имя глобального в качестве аргумента для этой функции:

someGlobal = 5;

function cantSeeThatGlobal(someGlobal) {
  console.log(someGlobal);
}

cantSeeThatGlobal();   // prints undefined
cantSeeThatGlobal(10); // prints 10

Лучше, конечно, просто не использовать глобальные переменные когда-либо.

0
задан helpdoc 18 January 2019 в 06:37
поделиться

2 ответа

class Item(scrapy.Item): 
  address = scrapy.Field()
  state = scrapy.Field()
  year = scrapy.Field(first), scrapy.Field(second)    #You dont need to do like this

class first(scrapy.Item):
  amounts = scrapy.Field()     #this work and below

class second(scrapy.Item):    #and yes this work, you can do it in spider level or pipelines, just make your desired data, and pas it to year variable as you want. it will accumulate that
  basic = scrapy.Field()
  information = scrapy.Field()

Позвольте мне привести вам пример,

first = {'first': first}
second = {'basic': basic, 'info': info}

year = {'first': first, 'second': second}
0
ответ дан ThunderMind 18 January 2019 в 06:37
поделиться
class Item(scrapy.Item): 
  address = scrapy.Field()
  state = scrapy.Field()
  year = scrapy.Field(serializer=dict)

class Year(scrapy.Item):
  first = scrapy.Field(serializer=dict)
  second = scrapy.Field(serializer=dict)

class first(scrapy.Item):
  amounts = scrapy.Field()

class second(scrapy.Item):
  basic = scrapy.Field()
  information = scrapy.Field()

Таким образом, вы можете сделать это:

>>> b = second(basic="hello", information="hello world")
>>> a = first(amounts=3)
>>> year = Year(first=a, second=b)
>>> year
{'first': {'amounts': 3},
 'second': {'basic': 'hello', 'information': 'hello world'}}
>>> item = Item(address='address value', state='state value', year=year)
>>> item
{'address': 'address value',
 'state': 'state value',
 'year': {'first': {'amounts': 3}, 'second': {'basic': 'hello', 'information': 'hello world'}}}
0
ответ дан VMRuiz 18 January 2019 в 06:37
поделиться
Другие вопросы по тегам:

Похожие вопросы: