为什么Eclipse每次尝试运行我的Python程序时都会要求'ant build'?

时间:2012-10-26 21:18:55

标签: python eclipse build ant pydev

我是新手编程并使用pydev在eclipse中运行我的python。我正在使用Eclipse EE和Python 2.7.3我试图运行的代码在这里:

def evaluate_poly(poly, x):

        sumPoly = 0

        for i in range(0,len(poly)):
            #calculate each term and add to sum.
            sumPoly = sumPoly+(poly[i]*x**i)
        return sumPoly




def compute_deriv(poly):

    derivTerm = ()

    #create a new tuple by adding a new term each iteration, assign to derivTerm each time.
    for i in range(0,len(poly)):
    #i is the exponent, poly[i] is the coefficient,
    #coefficient of the derivative is the product of the two.
        derivTerm = derivTerm + (poly[i]*i,)
    return derivTerm



def compute_root(poly, x_0, epsilon):

    #define root to make code simpler.
    root = evaluate_poly(poly,x_0)
    iterations = 0

    #until root (evaluate_poly) is within our error range of 0...
    while (root > epsilon) or (root < -epsilon):
    #...apply newton's method, calculate new root, and count iterations.
        x_0 = (x_0 - ((root)/(evaluate_poly(compute_deriv(poly),x_0))))
        root = evaluate_poly(poly,x_0)
        iterations = iterations + 1
    return (x_0,iterations)

print compute_root((4.0,3.0,2.0),0.1,0.0001)

每次我试图运行这个日食都要求我进行蚂蚁构建。当我点击确定没有任何反应。这只发生在我在函数内运行函数时,似乎非常基本的代码不是问题。出了什么问题,我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

如果只有函数,python就不会做任何事情。它不会毫无理由地运行任意函数。如果您想要打印出某些内容,则需要调用其中一项功能。最好的方法是将其添加到代码的底部:

if __name__ == '__main__':
    evaluate_poly([1, 2, 3], 4)