打印功能的缩进错误

时间:2014-05-02 03:46:18

标签: python

通常我用Java编写所有编程,但是我有一些python代码我转换为java。

我没有得到的是缩进样式,这很酷,因为这是python中完成事情的方式,我需要做的只是添加一个 一对print()函数代码只是为了确保我获得正确的结果。

例如

def relImgCoords2ImgPlaneCoords(self, pt, imageWidth, imageHeight):        
    ratio = imageWidth / float(imageHeight)
    sw = ratio
    sh = 1
    return [sw * (pt[0] - 0.5), sh * (pt[1] - 0.5)]

似乎无关紧要print函数如何缩进它显示缩进错误,这是什么诀窍?

    else:
        if scn.optical_center_type == 'camdata':
            #get the principal point location from camera data
            P = [x for x in  activeSpace.clip.tracking.camera.principal]
            #print("camera data optical center", P[:])
            P[0] /= imageWidth
            P[1] /= imageHeight
            #print("normlz. optical center", P[:])
            P = self.relImgCoords2ImgPlaneCoords(P, imageWidth, imageHeight)
        elif scn.optical_center_type == 'compute':
            if len(vpLineSets) < 3:
                self.report({'ERROR'}, "A third grease pencil layer is needed to compute the optical center.")
                return{'CANCELLED'}
            #compute the principal point using a vanishing point from a third gp layer.
            #this computation does not rely on the order of the line sets
            vps = [self.computeIntersectionPointForLineSegments(vpLineSets[i]) for i in range(len(vpLineSets))]
            vps = [self.relImgCoords2ImgPlaneCoords(vps[i], imageWidth, imageHeight) for i in range(len(vps))]
            P = self.computeTriangleOrthocenter(vps)
        else:
            #assume optical center in image midpoint
            pass

我希望看到vps变量的返回值在代码块的elif部分中,我在哪里调用print函数?

1 个答案:

答案 0 :(得分:2)

在您放置已注释的print语句的位置似乎没有任何问题。

最可能的情况是您将缩进与空格混合导致缩进错误。

尝试使用安装Python的reindent.py目录中的Tools/scripts脚本。