scrapy/scrapy — Issue #70: scrapy.item.Item - allow item.url along with item['url]
Author: warvariuc
Created: 2011-12-20 11:22:51+00:00
State: open

scrapy.item.Item:

def __getattr__(self, name):
if name in self.fields:
raise AttributeError("Use item[%r] to get field value" % name)
raise AttributeError(name)

def __setattr__(self, name, value):
if not name.startswith('_'):
raise AttributeError("Use item[%r] = %r to set field value" % \
(name, value))
super(DictItem, self).__setattr__(name, value)

I suggest to allow using `item.url=response.url` along with `item['url']` - this allows IDEs to autocomplete field names:

def __getattr__(self, name):
if name in self.fields:
return self.__getitem__(name)
raise AttributeError(name)

def __setattr__(self, name, value):
if not name.startswith('_'):
return self.__setitem__(name, value)
super(DictItem, self).__setattr__(name, value)