I am trying to batch load some dummy content from a CSV file into a development site to do some testing. I’m using Plone 4.0.1, with Python 2.6.5, on a Mac OS X 10.6.6.
1) I thought I would create a quick script that would iterate through a CSV file and then create some of my custom contenttypes: (Similar to http://plone.org/documentation/kb/batch-adding-users). In Plone 3, I had been able to parse CSV files in this fasion.
However, I got an AttributeError on split. I’m copying from my ipython (ipzope) testing:
>>> portal
<PloneSite at /Plone>
>>> portal['Scripts']['dummydata.csv']
<File at /Plone/Scripts/dummydata.csv>
>>> dummy = portal['Scripts']['dummydata.csv']
>>> dummy
<File at /Plone/Scripts/dummydata.csv>
>>> dummy.data.split('\n')
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
AttributeError: split
>>> dummy.split('\n')
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
AttributeError: split
2) Ultimately, I’d like to use csv from the standard library, which also did not work.
>>> import csv
>>> csv
<module 'csv' from '/Applications/Plone/Python-2.6/lib/python2.6/csv.pyc'>
>>> spamReader = csv.reader(dummy, delimiter=',', quotechar='"')
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
TypeError: argument 1 must be an iterator
>>> spamReader = csv.reader(dummy.data, delimiter=',', quotechar='"')
------------------------------------------------------------
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
TypeError: argument 1 must be an iterator
Any ideas?
Best,
Patrick
You could try something like this:
More info about python and csv can be found here: http://docs.python.org/library/csv.html
Bye,
Giacomo