Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow DelayedBase parameter in WriteToTextFileJob #546

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions text/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class WriteToTextFileJob(Job):

def __init__(self, content, out_name: str = "file.txt"):
"""
:param list|dict|str content: input which will be written into a text file
:param list|dict|str|DelayedBase content: input which will be written into a text file
BenediktConze marked this conversation as resolved.
Show resolved Hide resolved
:param out_name: user specific file name for the output file
"""
self.content = content
Expand All @@ -293,14 +293,15 @@ def tasks(self):
yield Task("run", mini_task=True)

def run(self):
content = util.instanciate_delayed(self.content)
with open(self.out_file.get_path(), "w") as f:
if isinstance(self.content, str):
f.write(self.content)
elif isinstance(self.content, dict):
for key, val in self.content.items():
if isinstance(content, str):
f.write(content)
elif isinstance(content, dict):
for key, val in content.items():
f.write(f"{key}: {val}\n")
elif isinstance(self.content, Iterable):
for line in self.content:
elif isinstance(content, Iterable):
for line in content:
f.write(f"{line}\n")
else:
raise NotImplementedError
Loading