I am trying to fill a file. When i am start the leading fuction the file schould be overwriting the , probarly, existing csv file. Accoording from keys from different keys in my sql files, information is collected and written in a other function.
I tried something like this <code> class BAGExtractPlus(wx.Frame): .......... #------------------------------------------------------------------------------ # schrijven van de records #------------------------------------------------------------------------------ def schrijfExportRecord(self,identificatie, hoofdadres, verblijfobjectgeometrie, dag): ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wa') verblijfhoofd = csv.writer(ofile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC) sql1=""; sql1="Select huisnummer, huisletter, huisnummertoevoeging, postcode, gerelateerdeopenbareruimte from nummeraanduiding " sql1a= "where aanduidingrecordinactief<> 'J' and" hsql1=" einddatum > '" + dag + "' and identificatie = '" + hoofdadres + "'"; sql1= sql1 + sql1a + hsql1; num= database.select(sql1); for row in num: huisnummer=row[0]; huisletter=row[1]; huisnummertoevoeging=row[2]; postcode=row[3]; gerelateerdeopenbareruimte=row[4]; sql2="Select openbareruimtenaam, gerelateerdewoonplaats from openbareruimte where aanduidingrecordinactief<> 'J'" sql2= sql2 + "and einddatum > '" + dag + "' and identificatie = '" + gerelateerdeopenbareruimte + "'"; opn=database.select(sql2); for row in database.select(sql2): openbareruimtenaam=row[0]; gerelateerdewoonplaats=row[1]; sql3="Select woonplaatsnaam from woonplaats where aanduidingrecordinactief<> 'J'" sql3= sql3 + "and einddatum > '" + dag + "' and identificatie = '" + gerelateerdewoonplaats + "'"; wpl=database.select(sql3); for row in wpl: woonplaatsnaam=row[0]; newrow=[identificatie, verblijfobjectgeometrie, huisnummer, huisletter, huisnummertoevoeging, postcode,openbareruimtenaam, woonplaatsnaam]; verblijfhoofd.writerow(newrow); del wpl[:]; del opn[:]; del num[:]; #-------------------------------------------------------------------------------------- # Exporteer benodigde gegevens #-------------------------------------------------------------------------------------- def ExportBestanden(self, event): ofile=open(r'D:\bestanden\BAG\adrescoordinaten.csv', 'wb') verblijfhoofd = csv.writer(ofile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC) dag=str(datetime.date.today()); sql4="Select adresseerbaarobjectnevenadres.identificatie, adresseerbaarobjectnevenadres.nevenadres from adresseerbaarobjectnevenadres where aanduidingrecordinactief<> 'J' order by adresseerbaarobjectnevenadres.identificatie" neven= database.select(sql4); for row in neven: nidentificatie=row[0]; nevenadres=row[1]; sql="Select identificatie, hoofdadres, ligplaatsgeometrie from ligplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "' and identificatie = '"+ nidentificatie + "'" lig= database.select(sql); for row in lig: hoofdadres=nevenadres; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) sql="Select identificatie, hoofdadres, verblijfsobjectgeometrie from verblijfsobject where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "' and identificatie = '"+ nidentificatie + "'" vbo= database.select(sql); for row in vbo: hoofdadres=row[1]; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) sql="Select identificatie, hoofdadres, standplaatsgeometrie from standplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "' and identificatie = '"+ nidentificatie + "'" stand= database.select(sql); for row in stand: hoofdadres=nevenadres; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) del stand[:]; del vbo[:]; del lig[:]; del neven[:]; sql="Select identificatie, hoofdadres, ligplaatsgeometrie from ligplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "'" lig= database.select(sql); for row in lig: hoofdadres=row[1]; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) del lig[:]; sql="Select identificatie, hoofdadres, standplaatsgeometrie from standplaats where aanduidingrecordinactief<> 'J' and einddatum >'" + dag + "'" stand= database.select(sql); for row in stand: hoofdadres=row[1]; identificatie=row[0]; verblijfobjectgeometrie=row[2]; self.schrijfExportRecord(identificatie, hoofdadres, verblijfobjectgeometrie, dag) del stand[:]; </code> The seems to work, but after 200.00 entries i got the message that opening is not allowed. What i am doing wrong? Is there a way to open the file once. When i didn't open it in the first part, it said it couldn't find the file.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor