Let the save text node save in csv format. (#15217)

This commit is contained in:
comfyanonymous 2026-08-01 19:27:37 -07:00 committed by GitHub
parent 41a3e160d7
commit e0951a9c7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 3 deletions

View File

@ -8,6 +8,13 @@ import folder_paths
class SaveTextNode(io.ComfyNode):
"""Save text content to .txt, .md, or .json."""
FORMAT_EXTENSIONS = {
"txt": "txt",
"csv": "csv",
"md": "md",
"json": "json",
}
@classmethod
def define_schema(cls):
return io.Schema(
@ -19,7 +26,7 @@ class SaveTextNode(io.ComfyNode):
inputs=[
io.String.Input("text", force_input=True),
io.String.Input("filename_prefix", default="ComfyUI"),
io.Combo.Input("format", options=["txt", "md", "json"], default="txt"),
io.Combo.Input("format", options=list(cls.FORMAT_EXTENSIONS), default="txt"),
],
outputs=[io.String.Output(display_name="text")],
is_output_node=True,
@ -27,6 +34,10 @@ class SaveTextNode(io.ComfyNode):
@classmethod
def execute(cls, text, filename_prefix, format):
extension = cls.FORMAT_EXTENSIONS.get(format)
if extension is None:
raise ValueError(f"Unsupported text format: {format!r}")
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(
filename_prefix,
folder_paths.get_output_directory(),
@ -34,10 +45,10 @@ class SaveTextNode(io.ComfyNode):
1,
)
file = f"{filename}_{counter:05}.{format}"
file = f"{filename}_{counter:05}.{extension}"
filepath = os.path.join(full_output_folder, file)
if format == "json":
if extension == "json":
# tries to pretty print otherwise saves normally
try:
data = json.loads(text)