Hi all,
this time I think I have a somewhat general problem, not S60 specific. But as people are so nice around here, I'll get on your nerves with this too...

I wonder why this little script here crashes everytime I exit it by any means:

Code:
#!/usr/bin/python
#Import a set of VCards in a file into the contacts database of a Series 60 Phone, esp. from Kontact (KDE)

import re, contacts, codecs, graphics, e32, appuifw

expremptyline = re.compile(r"\r\n\r\n", re.IGNORECASE & re.MULTILINE)
exprswitchtel = re.compile(r"TEL\;TYPE=", re.IGNORECASE & re.MULTILINE)

def exportforseries60(vcard):
 return exprswitchtel.sub(r"TEL;", vcard)

def readfile(filename):
 file = codecs.open(filename,"r","utf8")  
 inhalt = file.read()
 file.close()
 return inhalt

def writetext(s,clear = True,x = 0, y = 12):
 if clear: draw.clear()
 draw.text((x,y),s,0x008000)

def carryon(event):
 global lockjc
 lockjc.signal()

def quit():
 global lockjc
 lockjc.signal() #so it won't be locked in any case
 appuifw.app.exit_key_handler=None #don't know if this is necessary
 appuifw.app.set_exit()
 
appuifw.app.title=u"Import VCards"
canvas=appuifw.Canvas(event_callback=carryon)
appuifw.app.body=canvas
draw=graphics.Draw(canvas)

lockjc=e32.Ao_lock()
appuifw.app.exit_key_handler=quit

vcardstrings = expremptyline.split(readfile(r"e:\python\addressbook.vcf")) #last line is an empty newline (ist Kontact schuld)
writetext(u"%s VCards aus Datei geöffnet"%(len(vcardstrings)-1))

contactdb = contacts.open()
allenamen = contactdb.keys()
laengeallenamen = len(allenamen)
writetext(u"Es sind %s Kontakte im Telefonbuch vorhanden."%(laengeallenamen),False,0,24)
lockjc.wait()
for i in range(laengeallenamen):
 writetext(u"Lösche Kontakt Nr.: %s/%s"%(i+1, laengeallenamen))
 e32.ao_yield()
 del contactdb[allenamen[i]] #Missing here is the compact method to get the db-file small again (see other post of mine)

appuifw.note(u"Alle %s Kontakte gelöscht..."%(laengeallenamen),"info")

laengevcardstring = len(vcardstrings)
for g in range(laengevcardstring):
 writetext(u"Importiere VCard Nr.: %s/%s"%(g, laengevcardstring-1))
 contactdb.import_vcards(exportforseries60(vcardstrings[g]))
 e32.ao_yield()

allenamen = contactdb.keys()
laengeallenamen = len(allenamen)
contactdb.close()
appuifw.note(u"%s Kontakte importiert!"%(laengeallenamen),"info")
So, if anyone can enlighten me, please do! I have this (probably same) problem with some other scripts, too, and would like to get rid of it.

Thanks & bye,

Joost