我试图为我的画面工作表编写一个python脚本。它给我一个缩进错误

时间:2017-05-06 02:42:30

标签: python tableau tabpy

SCRIPT_BOOL("newList=[]
for x in _arg1:
newList.append(x > 0)
return newList
",SUM([Profit]))

处理脚本时出错 IndentationError:预期缩进块(第4行)

4 个答案:

答案 0 :(得分:2)

我不完全确定你在问什么,但尝试编写这样的脚本:

newList=[]
for x in _arg1:
    newList.append(x > 0)
return newList

有适当的缩进。

答案 1 :(得分:0)

如果您想要多行字符串,则必须使用语法"""I am a multiline string"""而不是"I am not a multiline string"

答案 2 :(得分:0)

通过快速阅读TabPy GitHub page,以下代码应该可以使用但未经测试,因此按原样提供:

SCRIPT_BOOL("newList=[]
for x in _arg1:
    newList.append(x > 0)
return newList",SUM([Profit]))

答案 3 :(得分:-2)

请改为:

SCRIPT_BOOL("return [i > 0 for i in _arg1]",SUM([Profit]))

调试比for循环更简单,更容易。但是如果你想要for-loop,你的第四行需要缩进,这样你的列表就会附加在你的循环中。

SCRIPT_BOOL(
"
newList=[]
for x in _arg1:
    newList.append(x > 0)
return newList
",SUM([Profit]))
BTW:Python社区对初学者非常不友好!在你投票之前,一个问题认为你也在某个地方开始了! ;(我不是唯一一个这样说的人(http://pythonforengineers.com/this-is-what-python-beginners-have-to-deal-with/