Ross Leung
03/29/2023, 7:29 PMdef 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"
Basically, I want to write to a file called task_out.txt
. I tried it without using the prefect LocalFileSystem
and simply used the with open
file context, but the file didn’t appear.Jarvis Stubblefield
03/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)
flow_files_path
…
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")
tmpchdir
functionality I pulled that directly from Prefect… from prefect.utilities.filesystem import tmpchdir
Ross Leung
03/31/2023, 12:28 AMos.getcwd()
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!