MCPcopy Create free account
hub / github.com/7BEII/Comfyui_PDuse / PD_StringLineCount

Class PD_StringLineCount

py/text_JoinStringMultiLine.py:46–82  ·  view source on GitHub ↗

接收字符串输入。 如果输入是列表(Batch),则统计列表中的项目数量。 如果输入是单个多行文本,则统计行数。 最终只输出一个整数 (Int)。

Source from the content-addressed store, hash-verified

44
45
46class PD_StringLineCount:
47 """
48 接收字符串输入。
49 如果输入是列表(Batch),则统计列表中的项目数量。
50 如果输入是单个多行文本,则统计行数。
51 最终只输出一个整数 (Int)。
52 """
53 def __init__(self):
54 pass
55
56 @classmethod
57 def INPUT_TYPES(s):
58 return {
59 "required": {
60 "text": ("STRING", {"forceInput": True, "multiline": True}),
61 }
62 }
63
64 # 【关键修改】开启列表模式,防止对列表中的每一项单独运行
65 INPUT_IS_LIST = True
66
67 RETURN_TYPES = ("INT",)
68 RETURN_NAMES = ("line_count",)
69 FUNCTION = "count_lines"
70
71 CATEGORY = "PD Nodes"
72
73 def count_lines(self, text):
74 # text 现在是一个列表 (list)
75 if not text:
76 return (0,)
77
78 # 获取列表长度 (即 Batch Size / 项目总数)
79 # 这样输入 3 个文件名时,就会直接返回 int 3
80 count = len(text)
81
82 return (count,)
83
84# --------------------------------------------------------------------------------
85# 节点注册映射

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected