0

I have a model with a list property.

I have a csv that has each list data that looks like this.

[u'1234567']

The list has only one item each.

My bulkloader.yaml has configured import_transform: transform.none_if_empty(list). It uploads the above list property as [u'[', u'u', u"'", u'1', u'2', u'3', u'4', u'5', u'6', u'7', u"'", u']']

How should I configure the import_transform in order to upload it properly?

Thanks!

Albert
  • 3,611
  • 3
  • 28
  • 52

2 Answers2

1

You can use json, it work for me. Like this:

import_transform: transform.none_if_empty(json.loads)
export_transform: transform.none_if_empty(json.dumps)

Remember to import json in python_preamble block.

Kevin Chiu
  • 11
  • 1
1

Try something like this:

import_transform: lambda x: [x] if x else None
Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
  • Didn't work for me yet. It says... Error parsing yaml file: Unable to asssign value 'lambda x' to attribute 'import_transform': Invalid code for import_transform. Code: "lambda x". Details: unexpected EOF while parsing <, line 1> Any ideas? – Albert Sep 01 '10 at 22:26
  • Hm. You may have to put the transform in a Python module, then import it and use it in the same way the bulkloader imports other modules in the yaml config. – Nick Johnson Sep 02 '10 at 08:47
  • You can quote the lambda expression and make it into a string, `import_transform: "lambda x: [x] if x else None"` – jsz Jul 02 '12 at 08:25