【问题标题】:writing output to files from python luigi从 python luigi 将输出写入文件
【发布时间】:2015-07-17 03:18:20
【问题描述】:

我只是尝试从文档中运行 python luigi example

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

我使用命令行运行它:

python Luigi_Test.py FlipLinesBackwards --local-scheduler

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

我做错了吗?

【问题讨论】:

  • 你的终端有执行错误吗?

标签: python luigi


【解决方案1】:

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

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

也就是说你要写文件xyz的内容

echo hi >> xyz
echo hello >> xyz

然后运行 ​​luigi 工作流程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-18
    • 2019-10-12
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多