adapt tutorial "Working with files" to the latest develop version

This commit is contained in:
Peter Uebele
2017-10-28 11:33:16 +02:00
parent a8ebc4d4d7
commit 9c5e98b18b
2 changed files with 4 additions and 4 deletions

View File

@ -2,14 +2,14 @@ import bonobo
def split_one(line): def split_one(line):
return line.split(', ', 1) return dict(zip(("name", "address"), line.split(', ', 1)))
graph = bonobo.Graph( graph = bonobo.Graph(
bonobo.FileReader('coffeeshops.txt'), bonobo.FileReader('coffeeshops.txt'),
split_one, split_one,
bonobo.JsonWriter( bonobo.JsonWriter(
'coffeeshops.json', fs='fs.output', ioformat='arg0' 'coffeeshops.json', fs='fs.output'
), ),
) )

View File

@ -11,7 +11,7 @@ def split_one_to_map(line):
class MyJsonWriter(bonobo.JsonWriter): class MyJsonWriter(bonobo.JsonWriter):
prefix, suffix = '{', '}' prefix, suffix = '{', '}'
def write(self, fs, file, lineno, row): def write(self, fs, file, lineno, **row):
return bonobo.FileWriter.write( return bonobo.FileWriter.write(
self, fs, file, lineno, json.dumps(row)[1:-1] self, fs, file, lineno, json.dumps(row)[1:-1]
) )
@ -20,7 +20,7 @@ class MyJsonWriter(bonobo.JsonWriter):
graph = bonobo.Graph( graph = bonobo.Graph(
bonobo.FileReader('coffeeshops.txt'), bonobo.FileReader('coffeeshops.txt'),
split_one_to_map, split_one_to_map,
MyJsonWriter('coffeeshops.json', fs='fs.output', ioformat='arg0'), MyJsonWriter('coffeeshops.json', fs='fs.output'),
) )