我目前正在使用脚本任务将jython嵌入到ant脚本中。它看起来像这样:
<target name="start">
<script language="jython">
print self.getProject().getProperty("antpropertytest")
</script>
</target>
然而,这给了我一个错误,因为我使用了一些制表符或空格来代替python代码,以便它适合于意图级别。当我使用下面的代码时
<target name="start">
<script language="jython">
print self.getProject().getProperty("antpropertytest")
</script>
</target>
然后它工作正常,但看起来搞砸了。有没有办法告诉python忽略每一行的前X个意图?或者还有另一种解决这个问题的方法吗?
答案 0 :(得分:0)
额外的if 1:
正在做这个伎俩:
<target name="start"> <property name="antpropertytest" value="true"/> <script language="jython">if 1: # just for indentation import sys def example(): print "sys.path:\n %s" % "\n ".join(sys.path) print "antpropertytest: %s" % self.getProject().getProperty("antpropertytest") example() </script> </target>