Merge pull request #207 from PeterUe/develop
adapt tutorial "Working with files" to the latest develop version
This commit is contained in:
@ -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'
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -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'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user