簡體   English   中英

IndentationError: 期望一個縮進塊 - 不知道這是從哪里來的

[英]IndentationError: expected an indented block - Don't know where this comes from

我構建了這個 function 並且不明白,為什么它不起作用:

def give_age_of(birthday):

    import datetime
    from dateutil.relativedelta import relativedelta

    aging = birthday
    totoday = datetime.date.today()
    age_of = relativedelta(totoday,aging).years

    return age_of
 File "<ipython-input-258-df8b9618ac1f>", line 5
    import datetime
    ^
IndentationError: expected an indented block

好的,我明白了,感謝 KlausD。 實際上不起作用的代碼如下,但我自己已經找到了解決方案。 我不得不刪除第 1 行的評論。

    # blablabla

def give_age_of(birthday):

    import datetime 
    from dateutil.relativedelta import relativedelta

    aging = birthday
    totoday = datetime.date.today()
    age_of = relativedelta(totoday,aging).years

    return age_of    

import 語句沒有縮進 python 通常會拋出一個錯誤,這些錯誤通常位於程序的頂部,所以它會是這樣的:

import datetime
def give_age_of(birthday):
    aging = birthday
    totoday = datetime.date.today()
    age_of = relativedelta(totoday,aging).years
    return age_of

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM