将输出写入python luigi的文件

Kil*_*ail 2 python luigi

我只是试图从文档中运行python luigi 示例:

class TaskA(luigi.Task):
    def output(self):
        return luigi.LocalTarget('xyz')

class FlipLinesBackwards(luigi.Task):
    def requires(self):
        return TaskA()

    def output(self):
        return luigi.LocalTarget('abc')

    def run(self):
        f = self.input().open('r') # this will return a file stream that reads from "xyz"
        g = self.output().open('w')
        for line in f:
           g.write('%s\n', ''.join(reversed(line.strip().split())))
        g.close() # needed because files are atomic
Run Code Online (Sandbox Code Playgroud)

我使用命令行运行它:

python Luigi_Test.py FlipLinesBackwards --local-scheduler
Run Code Online (Sandbox Code Playgroud)

我的印象是,这将在我运行它的目录中创建一个文件,但它没有?

难道我做错了什么?

Tar*_*sch 7

定义TaskA没有任何意义.它可能是一个ExternalTask.

class TaskA(luigi.ExternalTask):
    def output(self):
        return luigi.LocalTarget('xyz')
Run Code Online (Sandbox Code Playgroud)

这意味着您必须编写文件的内容 xyz

echo hi >> xyz
echo hello >> xyz
Run Code Online (Sandbox Code Playgroud)

然后运行luigi工作流程.