You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example in the document Item Exporters
called the file attribute of XmlItemExporter instance as follow:
def close_spider(self, spider):
for exporter in self.year_to_exporter.values():
exporter.finish_exporting()
exporter.file.close()
I checked the source of scrapy/scrapy/exporters.py,
actually, there is no attribute named 'file' in XmlItemExporter.
So, when i run the script the error occurred:
"AttributeError: 'XmlItemExporter' object has no attribute 'file'".
Also, there is no 'file' attribute in CsvItemExporter while exists in JsonItemExporter,
PickleItemExporter, MarshalItemExporter , PprintItemExporter.
I think it is necessary to and a file descriptor attribute into XmlItemExporter and CsvItemExporter for consistency. Also the file descriptor should be closed when exporting has been finished.
If the file descriptor attribute will add to XmlItemExporter and CsvItemExporter, then i have another question:
Is it a good idea to add the self.file.close() into the function finish_exporting()?
It seems it is simple for user just call function finish_exporting() and won't care about the file descriptor whether closed.
The text was updated successfully, but these errors were encountered:
I don't think anything should be done with existing exporters, as the file attribute is not documented and should not be accessed. The exporters use a file-like object opened by the outside code, so the same code should keep a reference and close it when needed. The reference is kept by some exporter classes because they need to access it, and other classes like XmlItemExporter and CsvItemExporter don't keep it because they keep a wrapper around it.
And I don't think an exporter should close a file-like object that was passed to it. This is not even possible in all cases, as currently we require only the write method to be present on the file-like object.
The example in the document Item Exporters
called the file attribute of XmlItemExporter instance as follow:
I checked the source of scrapy/scrapy/exporters.py,
actually, there is no attribute named 'file' in XmlItemExporter.
So, when i run the script the error occurred:
"AttributeError: 'XmlItemExporter' object has no attribute 'file'".
Also, there is no 'file' attribute in CsvItemExporter while exists in JsonItemExporter,
PickleItemExporter, MarshalItemExporter , PprintItemExporter.
I think it is necessary to and a file descriptor attribute into XmlItemExporter and CsvItemExporter for consistency. Also the file descriptor should be closed when exporting has been finished.
If the file descriptor attribute will add to XmlItemExporter and CsvItemExporter, then i have another question:
Is it a good idea to add the self.file.close() into the function finish_exporting()?
It seems it is simple for user just call function finish_exporting() and won't care about the file descriptor whether closed.
The text was updated successfully, but these errors were encountered: