Ich bin gerade dabei ein Programm zu schreiben, welches Daten aus einer RDF Datei holt.
An dieser Stelle
Code: Alles auswählen
if rgx_title.match(l):
res = rgx_title.match(l)
n["title"] = res.group(1)
Code: Alles auswählen
Traceback (most recent call last):
File "./urp", line 25, in ?
n["title"] = res.group(1)
TypeError: object does not support item assignment
Code: Alles auswählen
#!/usr/bin/python
import sys, re, urllib
rgx_title_u = '<title>(.*)</title>'
rgx_link_u = '<link>(.*)</link>'
rgx_desc_u = '<description>(.*)</link>'
rgx_url_u = '<url>(.*)</url>'
rgx_title = re.compile(rgx_title_u)
rgx_link = re.compile(rgx_link_u)
rgx_desc = re.compile(rgx_desc_u)
rgx_url = re.compile(rgx_url_u)
url = urllib.urlopen("symlinkch.rdf")
for l in url.readlines():
l = l.strip()
if l == "<channel>": n = {}
elif l == "</channel>":
n = None
if rgx_title.match(l):
res = rgx_title.match(l)
n["title"] = res.group(1)
elif rgx_link.match(l):
res = rgx_link.match(l)
n["link"] = res.group(1)
elif rgx_desc.match(l):
res = rgx_desc.match(l)
n["desc"] = res.group(1)
elif rgx_url.match(l):
res = rgx_url.match(l)
n["url"] = res.group(1)
url.close()
Jochen