Search code examples
pythonlisticalendarpypi

Access property in Pypi ics


When using the ics library found here I run into a problem I can't figure out. When accessing a index i.e. cal.events[9].name I can access the information. When I run over that events list I can't access the information and I get this error: AttributeError: 'str' object has no attribute 'name'

from ics import Calendar
from urllib.request import urlopen

url = "http://www.limburg.net/ics/afvalkalender/72004/15014/24/0"
cal = Calendar(urlopen(url).read().decode('iso-8859-1'))

print(cal.events[10].name)

for events in cal:
   print(events.name)

Solution

  • I'm not familiar with that specific library, but it looks like you meant to iterate over cal.events instead of cal:

    for event in cal.events:
        print(event.name)