我正在尝试运行一个脚本(我发现here),该脚本读取.ics文件(从Google日历获取)。这是代码:
from icalendar import Calendar
import urllib
ics = urllib.urlopen('http://www.google.com/calendarlink/basic.ics').read()
ical=Calendar.from_string(ics)
for vevent in ical.subcomponents:
if vevent.name != "VEVENT":
continue
title = str(vevent.get('SUMMARY'))
description = str(vevent.get('DESCRIPTION'))
location = str(vevent.get('LOCATION'))
start = vevent.get('DTSTART').dt # a datetime
end = vevent.get('DTEND').dt # a datetime
我在easy_install上安装了icalendar,但是当我运行scrpt时,出现此错误:
C:\python test>c:\Python27\python.exe google-calendar-test.py
Traceback (most recent call last):
File "google-calendar-test.py", line 4, in <module>
ical = Calendar.from_string(ics)
AttributeError: type object 'Calendar' has no attribute 'from_string'
我还没有在Linux上测试过它,但是我确信它可以在Linux上运行。几个月前,我在另一个软件包中遇到了同样的问题。似乎是个错误?有人有主意吗?
最佳答案
根据文档,Calendar.from_string
是deprecated on 2012-09-15。再往下看,您应该改为使用Calendar.from_ical
。
关于python - icalendar没有属性“from_string”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21946174/