0

インポートを from-import として変更した後、次のエラーが発生します。

from datetime import datetime, date, timedelta
today = date.today()
from time import mktime
from feedparser import feedparser
import settings

def check_calendar():
    d = feedparser.parse(settings.personal_calendar_feed)
    for entry in d.entries:
        if(date.fromtimestamp(mktime(entry.date_parsed))==today):

Traceback (most recent call last):
  File computer.py", line 734, in <module>
    check_calendar()
  File "computer.py", line 210, in check_calendar
    if(date.fromtimestamp(mktime(entry.date_parsed))==today):
AttributeError: 'function' object has no attribute 'fromtimestamp'
4

2 に答える 2

3

それは言う

AttributeError:'関数'オブジェクトに属性'fromtimestamp'がありません

エラーで。どうやらあなたはあなたのコードに「date」という名前の関数を持っているかもしれません。Pythonでは任意の名前を使用できるため、競合する新しい名前は古い名前を上書きします。

代わりに、Pythonがモジュールまたはオブジェクトから関数を見つけることができない場合、「fromtimes」を呼び出したい場合のように、通常、タイプオブジェクトに属性がないか、モジュールに属性がないと表示されます。

タイプオブジェクト'datetime.date'には属性'fromtimes'がありません

コードをもう一度注意深く確認することをお勧めします。

于 2012-04-08T20:27:02.860 に答える
3

コードの前の方でdate関数として再宣言している可能性が高いです。def date():そうでなければ意味がありません。

于 2012-04-08T20:25:13.233 に答える