2017-07-28 236 views
-2

當我執行這個代碼,我得到的錯誤IndentationError: unindent does not match any outer indentation levelUDF:IndentationError:取消縮進不匹配任何外部縮進級別

def calculate(num1, num2): 
    if (num1/num2 > 1): 
     num1 = num2 
    result = (num1 - num2)/math.sqrt(1-(num1/num2)) 
    return result 
df = udf(calculate, FloatType()) 

我在做什麼錯?

+0

哪裏出錯?我只是將你的函數複製並粘貼到一個ipython會話中,它對我來說工作得很好。最後一行看起來像是需要從其他庫中導入,所以我沒有嘗試執行它。 –

+0

這段代碼中沒有縮進問題。 –

+2

您可能會混合製表符和空格。在這裏發佈代碼時,我看到標籤轉換爲空格。 – Goyo

回答

0

您發佈的代碼沒有縮進錯誤。查看錯誤消息中報告的行號。你會看到類似這樣的東西:

xxxx 
    xxxxx 
    xxxxx 
    xxxxx 
^this is the unindent that is causing the problem 
+0

我得到這個:'df = udf(calculate,FloatType())^'。符號'^'放在最後'''下面。 – Dinosaurius

相關問題