可以像这样output()
压缩文件:
def output(self):
date_path = self.search['date_path']
zip_fn = "data/%s/%s.zip" % (date_path, date_path)
return luigi.LocalTarget(zip_fn)
但是如何使用run()
方法粘贴此邮政编码?
class ZeroTask(luigi.Task):
path_in = luigi.Parameter()
textfiles = []
path_to_zip = ''
def requires(self):
return []
def run(self):
# Get bunch of text files
# some manipulations with textfiles
# Create a result.zip
# self.path_to_zip = '~/Project/result.zip'
def output(self):
zip_fn = self.path_to_result.zip
return luigi.LocalTarget(zip_fn)
用run()
方法做什么?
答案 0 :(得分:1)
您应该可以根据需要使用zipfile
来构建文件。
class MyTask(luigi.Task):
def output(self):
date_path = self.search['date_path']
zip_fn = "data/%s/%s.zip" % (date_path, date_path)
return luigi.LocalTarget(zip_fn)
def run(self):
ztemp = tempfile.NamedTemporaryFile(mode='wb')
z = zipfile.ZipFile(ztemp, 'w')
# build the zip file
z.close()
os.rename(ztemp.name, self.output().path)