在n8n的 Python代码节点中,如何从Google表格获取列名及其对应的值?

编程语言 2026-07-09

我需要遍历从Google表格中检索到的所有列,并通过如下代码块来获取它们的名称和值:

data = _input.all()

for item in data:
    row = item["json"]

    for column_name, value in row.items():
        print(f"Столбец: {column_name}")
        print(f"Значение: {value}")

Im using this code in an n8n environment, but I got an error saying_input` 不存在。 那么,我该如何遍历所有列名及它们的值呢?

解决方案

Information for other users:

问题已在n8n论坛上解决:
How to get column names and values from Google Sheets in Python Code node n8n?

Solution: If you use Run Once For Each Item then it needs _item instead of _inputs

Code from n8n forum:

row = _item["json"]
for column_name, value in row.items():
    print(f"Column: {column_name}")
    print(f"Value: {value}")

return _item

It seems for Run Once For All Items it may also need _items instead of _inputs

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章