Ross Leung03/29/2023, 7:29 PM
Basically, I want to write to a file called
def task_1(): from prefect.filesystems import LocalFileSystem fs = LocalFileSystem(basepath="./") with open("task_out.txt","w") as f: f.writelines('Hi') fs.write_path(path="task_out.txt",content=f) return "task_out.txt"
. I tried it without using the
and simply used the
file context, but the file didn’t appear.
Jarvis Stubblefield03/30/2023, 4:23 PM
@task def write_log_report_to_file(filename: str, fieldnames: List[str], logs_report: List[dict]) -> None: with tmpchdir(flow_files_path): with open(filename, 'w') as csvfile: # This is for MS Excel csvfile.write(u'\ufeff') writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for report in logs_report: writer.writerow(report)
from tenzinga_django_setup import prepare_django_and_paths tenzinga_path, ppower_path = prepare_django_and_paths() flow_files_path = tenzinga_path.joinpath("web-write").joinpath("flow-files")
functionality I pulled that directly from Prefect…
from prefect.utilities.filesystem import tmpchdir
Ross Leung03/31/2023, 12:28 AM
and indeed my flow is ran in a tmp folder that disappears. I also confirmed that if I put a full local directory path instead of a relative path, the output goes to the right location too. Thanks!