【问题标题】:Set Jython standard indentation level for using in ant设置 Jython 标准缩进级别以在 ant 中使用
【发布时间】:2013-11-12 14:06:16
【问题描述】:

我目前正在使用脚本任务将 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 意图?或者这个问题有其他解决方案吗?

【问题讨论】:

    标签: python ant coding-style jython indentation


    【解决方案1】:

    一个额外的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>
    

    【讨论】:

      猜你喜欢
      • 2013-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-11
      • 2011-02-12
      • 1970-01-01
      • 2023-03-20
      相关资源
      最近更新 更多